Remove the translucent effect to UINavigationBar of MFMailComposeViewController
Asked Answered
S

4

12

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 ?

Siegler answered 3/10, 2013 at 6:35 Comment(3)
Hello, did you find solution?Rasputin
No, I didn't. Not sure it's possible.Siegler
Have you tried hiding it and reinstating it ? This seems a problem in iOS with modal view controllers. I gave up and started hiding and reinstating in viewwillappear and viewwilldisappear. [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];Sokotra
C
1

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.

Comose answered 26/9, 2014 at 17:27 Comment(0)
C
0

I think I read somewhere that Apple does not want us to customize that ViewController much, but beside that the accepted SO anser over here might help: MFMailComposeViewController in iOS 7 statusbar are black

…because of timing issues.

Coughlin answered 2/12, 2013 at 15:58 Comment(0)
V
0
MFMailComposeViewController *mailVC = [[MFMailComposeViewController alloc] init];
[self.navigationController presentViewController:mailVC animated:YES completion:^{
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}];

if don't want it to change globally :

Try to add category to MFMailComposeViewController

@implementation MFMailComposeViewController (IOS7_StatusBarStyle)

-(UIStatusBarStyle)preferredStatusBarStyle
{
   return UIStatusBarStyleLightContent;
}

-(UIViewController *)childViewControllerForStatusBarStyle
{
   return nil;
}

@end
Vandervelde answered 30/7, 2014 at 10:47 Comment(0)
E
0

This isn't something that can fit into a few lines of code, but this is one approach that might work for you.

To hide the navigation bar:

[[self navigationController] setNavigationBarHidden:YES animated:YES];

To show it:

[[self navigationController] setNavigationBarHidden:NO animated:YES];

Documentation for this method is available here.

To listen for a "double click" or double-tap, subclass UIView and make an instance of that subclass your view controller's view property.

In the view subclass, override its -touchesEnded:withEvent: method and count how many touches you get in a duration of time, by measuring the time between two consecutive taps, perhaps with -timeIntervalSinceDate:. Or test the result from [touch tapCount].

If you get two taps, your subclassed view issues an NSNotification that your view controller has registered to listen for.

When your view controller hears the notification, it fires a selector that either hides or shows the navigation bar using the aforementioned code, depending on the navigation bar's current visible state, accessed through reading the navigation bar's isHidden property.

Extravagant answered 12/8, 2014 at 11:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.