Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove the translucent effect to UINavigationBar of MFMailComposeViewController

I didn't find the way to remove the translucent effect (iOS 7) to the UINavigationBar of MFMailComposeViewController. No problem for all other UINavigationBars in my app.

I tried this without success:

MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.navigationBar.translucent = NO;

Any idea ?

like image 657
alex.bour Avatar asked Oct 03 '13 06:10

alex.bour


People also ask

How do I make my navigation bar clear?

You need to do three things to make a navigation bar transparent. Set background image to non-nil empty image ( UIImage() ). Set shadow image to non-nil empty image ( UIImage() ). Set isTranslucent to true .

What is translucent in Swift?

A Boolean value that indicates whether the navigation bar is translucent.


1 Answers

A bit late, but for whoever comes across this post:

By default, the MFMailComposeViewController's navigationBar is going to be translucent and you can't change that. The only properties that you can change are the ones supported by the Appearance Proxy. From Apple Documentation:

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.

That leaves you with limited options to change your MFMailComposeViewController's Navigation Bar Appearance, as not all properties are supported (e.g. if you try something like [UINavigationBar appearance] setTranslucent:NO]; it'll crash, because this property is not supported by the proxy.

Here's a list of properties supported by the Appearance proxy: https://gist.github.com/mattt/5135521

Now, to set the MFMailComposeViewController's navigationBar to be non-translucent, you need to change its backgroundColor (It's an UIView allowed property, UINavigationBar is a subclass of UIView):

[[UINavigationBar appearance] setBackgroundColor:[UIColor whiteColor]];

Make sure you do this before you instantiate your MFMailComposeViewController, for example:

[[UINavigationBar appearance] setBackgroundColor:[UIColor whiteColor]];
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];

You can also use appearanceWhenContainedIn:MFMailComposeViewController, to affect the navBar only when it's being owned by a MFMailComposeViewController, or you can optionally change it back to whatever it was before in mailComposeController:didFinishWithResult.

like image 107
Carlos Conejo Avatar answered Sep 18 '22 13:09

Carlos Conejo