15

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

请帮我。谢谢

4

4 回答 4

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

[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];

或者

navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor yellowColor] forKey:UITextAttributeTextColor];

希望它对你有用..

于 2012-06-12T12:51:09.657 回答
15

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

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[[picker navigationBar] setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:NSForegroundColorAttributeName]];

原因如下:

上面的复选标记答案(由 Mani 引用)[UINavigationBar appearance]是不正确的,因为它也会改变UINavigationBar正在弹出的标题的颜色MFMailComposeViewController,这是我不想要的效果。您需要像我的代码一样专门获取选择器的 NavBar。

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

另外,UITextAttributeTextColor现在已弃用,请使用NSForegroundColorAttributeName.

于 2014-04-24T15:36:52.653 回答
10
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc]init];
    picker.mailComposeDelegate = self;
    [[picker navigationBar] setTintColor:[UIColor blackColor]];
于 2012-06-12T12:25:31.163 回答
0

对于黑色以外的颜色,请使用以下代码:

MFMailComposeViewController *mailController  = [MFMailComposeViewController new];

            [mailController.navigationBar setTintColor:[UIColor colorWithHue:240.0f/359.0f
                                                                  saturation:85.0f/100.0f 
                                                                  brightness:60.0f/100.0f 
                                                                       alpha:0.0f]];
于 2012-06-26T07:26:10.730 回答