Change navigation button color in MFMailComposerViewController on iOS 7

OemerA picture OemerA · Oct 12, 2013 · Viewed 10.7k times · Source

I'm trying to change the text color for navigation buttons in a MFMailComposerViewController but it doesn't work like on iOS 6. In iOS 6 it worked with UIAppearance like this:

// Navigation button
UIBarButtonItem *barButton = [UIBarButtonItem appearance];
NSDictionary *barButtonTitleTextAttributes = @{UITextAttributeTextColor: [UIColor redColor]};
NSDictionary *disabledBarButtonTitleTextAttributes = @{UITextAttributeTextColor: [UIColor grayColor]};

[barButton setTitleTextAttributes:barButtonTitleTextAttributes forState:UIControlStateNormal];
[barButton setTitleTextAttributes:disabledBarButtonTitleTextAttributes forState:UIControlStateDisabled];
[barButton setBackgroundImage:[[UIImage imageNamed:@"btn_appearance"] stretchableImageWithLeftCapWidth:6 topCapHeight:0] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

But this doesn't work on iOS 7 and looks always like this: enter image description here

I also tried to set the tintColor attribute on the navigationBar but this has no effect either:

navigationBar.tintColor = [UIColor redColor];

Is there anyway to change the navigation button text color in a MFMailComposeViewController on iOS 7?

Answer

Javi Campaña picture Javi Campaña · Jan 17, 2014

I used this and works perfect in iOS7+

MFMailComposeViewController* mailViewController = [[MFMailComposeViewController alloc] init];        
mailViewController.mailComposeDelegate = self;
[mailViewController setToRecipients:@[@"[email protected]"]];

[mailViewController.navigationBar setTintColor:[UIColor orangeColor]];

[self presentViewController:mailViewController animated:YES completion:nil];