19

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
iYassin
  • 552
  • 1
  • 10
  • 21

6 Answers6

39

Here you go:

[[picker navigationBar] setTintColor:[UIColor blackColor]];

for iOS 8.0

 [[picker navigationBar] setBarTintColor:[UIColor blackColor]];
amit gupta
  • 1,167
  • 12
  • 29
Sindre Sorhus
  • 62,972
  • 39
  • 168
  • 232
  • Thank you for the tip. It was already posted as a comment above, but now I could mark the question as solved ;-) – iYassin Nov 16 '09 at 16:27
  • 2
    For iOS 7.0 apps, this doesn't work. Look at the note from eggboxderek. – Nick N May 20 '14 at 16:19
  • setTintColor now changes the bar buttons so you would normally use setBarTintColor on a viewcontroller, however this does not work for the MFMailComposeViewController. – Leon Jul 13 '15 at 10:08
12

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.

5

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 
Erhan Demirci
  • 4,173
  • 4
  • 36
  • 44
3

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.

Phil Viso
  • 643
  • 7
  • 11
2

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

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.

kevin
  • 75
  • 5