在MFMailComposeViewController中更改导航的主标题颜色

use*_*163 15 iphone xcode cocoa-touch objective-c

我对普通viewController的导航主标题的更改颜色没有问题,但在MFMailComposeViewController上,它是不可能的.我可以改变按钮的颜色(取消和发送),我可以设置导航栏的背景但不能改变标题的颜色.我不想设置一个新标题(显然,Apple不允许),我只想改变颜色:'(

请帮我.谢谢

Man*_*ani 15

NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                            [UIColor whiteColor],UITextAttributeTextColor, 
                                            [UIColor blackColor], UITextAttributeTextShadowColor, 
                                            [NSValue valueWithUIOffset:UIOffsetMake(-1, 0)], UITextAttributeTextShadowOffset, nil];

[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
Run Code Online (Sandbox Code Playgroud)

要么

navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor yellowColor] forKey:UITextAttributeTextColor];
Run Code Online (Sandbox Code Playgroud)

希望它为你工作..

  • 这会在整个应用程序中更改颜色,但不会在MFMailComposure中更改.IOS 12. (4认同)

Eth*_*len 15

这是iOS 7,8,9和10的正确答案:

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[[picker navigationBar] setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:NSForegroundColorAttributeName]];
Run Code Online (Sandbox Code Playgroud)

原因如下:

支票标注答案以上(玛尼)引用[UINavigationBar appearance]是不正确的,它会改变标题的颜色UINavigationBar被弹出的MFMailComposeViewController为好,这是我不希望的效果.您需要像我的代码那样专门获取选择器的NavBar.

tintColor从iOS 7(Mani的另一个答案)设置也是不正确的,因为它设置了按钮的颜色,而不是标题.

此外,UITextAttributeTextColor现已弃用,请使用NSForegroundColorAttributeName.


Man*_*ani 10

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc]init];
    picker.mailComposeDelegate = self;
    [[picker navigationBar] setTintColor:[UIColor blackColor]];
Run Code Online (Sandbox Code Playgroud)