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:
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?
As has been pointed out a few times, setting the tint on the MFMailComposeViewController navigation bar does not work. If you have other appearance changes set for the whole app, the tint colour is only one aspect of the issue, in our app we have changed the bar colour and UIBarButton text size so in the MFMailComposeViewController we see this:
The appearance in our app is set in a StyleGuide class with a function
configureAppearanceModifiers
called from the AppDelegate.Taking the example from @timosdk I have added a second method:
I call this before initialising the MFMailComposeViewController and then call
configureAppearanceModifiers
again in thedidFinishWithResult
delegate before dismissing the ViewController, this works perfectly.If you ever inspect the view hierarchy created by showing a MFMailComposeViewController you'll see that it's contained within an instance of _UITextEffectsRemoteView. You have zero programmatic access to any subviews of that, which I'm guessing is because they're probably owned by a separate process. Those subviews will inherit anything set on the various UIAppearance proxies (e.g., bar background, titleTextAttributes, etc) but nothing more.
The UIAppearance protocol does not mention this in the documentation, but it does have this in the comments of the header file:
So the end result is that while you can control most aspects of the appearance of MFMailComposeViewController you will always get the system default blue tint color.
Bug report: http://openradar.appspot.com/radar?id=6166546539872256
Like OemerA says - there is no way to change the colors. My problem was that in UIAppearance I set the background color of the bar to blue so then the "buttons" are no longer visible. Since the email is actually not part of your app it makes more sense to reset the nag bar appearance prior to creating the mail composer. This is how I do it:
Swift 3.0
If you set the tintColor on UIWindow it works perfectly fine, the first time presenting the MFMailComposerViewController. It seems like it loses the tintColor information for the subsequent calls.
Note: this changes the tint of every element of your window.
I used this and works perfect in iOS7+