问题
I'm using a tinted navigation bar and a tinted global UIToolbar in my iPhone app. In my info view, I have a button which opens a MFMailComposeViewController, and the toolbar at the top of that view (with the "cancel" and "send" button) is still blue. I'm calling the MFMailComposeViewController like this:
-(void)displayMailSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"..."];
NSArray *toRecipients = [NSArray arrayWithObject:@"..."];
[picker setToRecipients:toRecipients];
[self presentModalViewController:picker animated:YES];
[picker release];
}
Is it possible to change the color of that view's toolbar? If it is possible, how can I do this?
回答1:
Here you go:
[[picker navigationBar] setTintColor:[UIColor blackColor]];
for iOS 8.0
[[picker navigationBar] setBarTintColor:[UIColor blackColor]];
回答2:
A minor point about this functionality under iOS7 - the tint color property no longer affects the colour of the bar as a whole, instead it simply changes the colour of the 'Send' and 'Cancel' buttons (which, in iOS7 style, are simply tinted labels).
This is worth noting if you have changed the title bar colour to something like white or clear, as under iOS7 the send and cancel buttons will no longer be visible.
回答3:
you can do it globally from appdelegate
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigationbar-background.png"] forBarPosition:UIBarPositionTopAttached barMetrics:UIBarMetricsDefault]; // MFMailComposeViewController's navigationBar backgroundcolor
NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor], UITextAttributeTextColor, [UIColor whiteColor], UITextAttributeTextShadowColor, nil];
[[UINavigationBar appearance] setTitleTextAttributes:textTitleOptions];//MFMailComposeViewController's navigationBar text color
回答4:
Just want to emphasize that the above post about Apple rejecting your application is an old post. Here is a quote from the current MFMailComposeViewController documentation...
Important: The view hierarchy of this class is private and you must not modify it. You can, however, customize the appearance of an instance by using the UIAppearance protocol.
回答5:
Try this:
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]];
回答6:
From the official MFMailComposeViewController Class reference:
Important: The mail composition interface itself is not customizable and must not be modified by your application. [...]
I think it would be a better choice presenting the default mail composition interface without any changes. Otherwise Apple may reject your application.
Let's ask here if someone had an experience in this way.
来源:https://stackoverflow.com/questions/1634417/changing-mfmailcomposeviewcontrollers-toolbar-color