Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change main title color of navigation in MFMailComposeViewController

I haven't problem for change color of main title of navigation on a normal viewController but on a MFMailComposeViewController, it isn't possible. I can change colors of buttons (cancel and send), I can set background of navigation bar but not possible to change color of title. I don't want set a new title (apparently, it's not allow by Apple), I just want change the color :'(

Please help me. Thanks

like image 941
user1451163 Avatar asked Jun 12 '12 12:06

user1451163


People also ask

How to change the color of navigation bar and title text?

To change the color of the navigation bar and the title text, we can use UINavigationBarAppearance, which is available since iOS 13. We hereby make a class Theme with a static method as follows, which will come in handy when we need it for some setup in our View or elsewhere.

What is mailcomposedelegate mfmailcomposeviewcontrollerdelegate?

var mailComposeDelegate: MFMailComposeViewControllerDelegate? A standard view controller, whose interface lets the user manage, edit, and send email messages. Use this view controller to display a standard email interface inside your app.

Should I configure the fields of my email before presenting the controller?

Therefore, always configure the fields of your email before presenting the view controller. The mail compose view controller is not dismissed automatically. When the user taps the buttons to send the email or cancel the interface, the mail compose view controller calls the mailComposeController (_:didFinishWith:error:) method of its delegate.

How can I customize the appearance of the email interface?

However, you can customize the appearance of the interface using the UIAppearance protocol. An alternate way to compose emails is to create and open a URL that uses the mailto scheme. URLs of that type are directed to the built-in Mail app, which uses your URL to configure a message.


2 Answers

NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                            [UIColor whiteColor],UITextAttributeTextColor, 
                                            [UIColor blackColor], UITextAttributeTextShadowColor, 
                                            [NSValue valueWithUIOffset:UIOffsetMake(-1, 0)], UITextAttributeTextShadowOffset, nil];

[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];

Or

navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor yellowColor] forKey:UITextAttributeTextColor];

Hope its work for you..

like image 107
Mani Avatar answered Sep 22 '22 10:09

Mani


This is the correct answer for iOS 7, 8, 9, and 10:

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[[picker navigationBar] setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:NSForegroundColorAttributeName]];

Here is why:

The check marked answer above (by Mani) referencing [UINavigationBar appearance] is incorrect as it will change the color of the title in the UINavigationBar that is popping the MFMailComposeViewController as well, which was an effect I didn't want. You need to specifically get the picker's NavBar as my code does.

Setting tintColor is also incorrect as of iOS 7 (the other answer by Mani) as it sets the colors of the buttons, not the title.

Also, UITextAttributeTextColor is now deprecated, please use NSForegroundColorAttributeName.

like image 41
Ethan Allen Avatar answered Sep 22 '22 10:09

Ethan Allen