Changing MFMailComposeViewController's toolbar color
Asked Answered
C

6

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?

Conventionalize answered 27/10, 2009 at 23:59 Comment(1)
Have you tried setting picker.navigationBar.tintColor?Ciaracibber
O
39

Here you go:

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

for iOS 8.0

 [[picker navigationBar] setBarTintColor:[UIColor blackColor]];
Opinicus answered 15/11, 2009 at 15:38 Comment(3)
Thank you for the tip. It was already posted as a comment above, but now I could mark the question as solved ;-)Conventionalize
For iOS 7.0 apps, this doesn't work. Look at the note from eggboxderek.Husein
setTintColor now changes the bar buttons so you would normally use setBarTintColor on a viewcontroller, however this does not work for the MFMailComposeViewController.Schreiner
A
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.

Allogamy answered 1/10, 2013 at 9:41 Comment(0)
P
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 
Palter answered 19/11, 2013 at 15:37 Comment(0)
S
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.

Slopwork answered 7/11, 2013 at 7:29 Comment(0)
R
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]];
Reich answered 26/6, 2012 at 7:29 Comment(0)
M
-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.

Mundt answered 20/12, 2009 at 18:7 Comment(1)
you can do it with globally from appdelegate.Palter

© 2022 - 2024 — McMap. All rights reserved.