Cody Winton
Cody Winton

Reputation: 2989

Remove Custom Nav Bar on Email Sheet

I have this code in my App Delegate:

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"Nav Bar.png"] forBarMetrics:UIBarMetricsDefault];

This works great, but I use the MFMailComposeViewController and I want it to have the default NavigationBar appearance.

How do I do that?

EDIT:

I tried this code:

[[UINavigationBar appearanceWhenContainedIn: [MFMailComposeViewController class], [UIViewController class], nil] setBackgroundImage:[UIImage imageNamed:@"Textured Background.png"] forBarMetrics:UIBarMetricsDefault];

I've also tried having only this code. Nothing changes. Default Nav bar, including with the Mail View Controller.

I think it could be something with the appearanceWhenContainedIn:. Does anyone know what MFMailComposeViewController would be contained in?

Upvotes: 1

Views: 1196

Answers (2)

Cody Winton
Cody Winton

Reputation: 2989

I figured it out! Here's the code:

[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
MFMailComposeViewController *emailVC = [[MFMailComposeViewController alloc] init];
//the rest of the implementation goes here...
[self presentViewController:emailVC animated:YES completion:nil];

Then, I set the nav bar appearance back to normal here:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"Nav Bar.png"] forBarMetrics:UIBarMetricsDefault];
    [self dismissViewControllerAnimated:YES completion:nil];
}

Upvotes: 6

Oscar Gomez
Oscar Gomez

Reputation: 18488

You can try this:

[UINavigationBar appearanceWhenContainedIn: [MFMailComposeViewController class], nil]

Which means all navigation bars contained in a MFMailComposeViewController class

From the docs: UIAppearance

This will return the appearance proxy so you can modify it like this:

[[UINavigationBar appearanceWhenContainedIn: [MFMailComposeViewController class], nil] setBackgroundImage:myImage];

Hope that helps.

Upvotes: 0

Related Questions