15

I haven't problem for change color of main title of navigation on a normal viewController but on a MFMailComposeViewController, it isn't possible. I can change colors of buttons (cancel and send), I can set background of navigation bar but not possible to change color of title. I don't want set a new title (apparently, it's not allow by Apple), I just want change the color :'(

Please help me. Thanks

user1451163
  • 173
  • 1
  • 4
  • Refer to this link: http://stackoverflow.com/questions/1634417/changing-mfmailcomposeviewcontrollers-toolbar-color – Dee Jun 12 '12 at 12:23

4 Answers4

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

[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];

Or

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

Hope its work for you..

Mani
  • 1,841
  • 15
  • 29
15

This is the correct answer for iOS 7, 8, 9, and 10:

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

Here is why:

The check marked answer above (by Mani) referencing [UINavigationBar appearance] is incorrect as it will change the color of the title in the UINavigationBar that is popping the MFMailComposeViewController as well, which was an effect I didn't want. You need to specifically get the picker's NavBar as my code does.

Setting tintColor is also incorrect as of iOS 7 (the other answer by Mani) as it sets the colors of the buttons, not the title.

Also, UITextAttributeTextColor is now deprecated, please use NSForegroundColorAttributeName.

Ethan Allen
  • 14,425
  • 24
  • 101
  • 194
10
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc]init];
    picker.mailComposeDelegate = self;
    [[picker navigationBar] setTintColor:[UIColor blackColor]];
Mani
  • 1,841
  • 15
  • 29
  • It's not what I search, here you change the color of navigation bar (I've already a background for that), I want to change the color of titleview – user1451163 Jun 12 '12 at 12:47
0

For colors other than black, play around with this code:

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]];
Matt
  • 74,352
  • 26
  • 153
  • 180
DataPriest
  • 1,129
  • 8
  • 8