UIAppearance Remove Custom NavBar Background for MFMailComposeViewController
Asked Answered
B

2

6

I have a custom navBar image in the navigation controllers in my app, set using UIAppearance protocol. However, when sending mail through the app (via MFMailComposeViewController), I want the default navBar instead of the custom one. I tried the approach outlined in this question: UIAppearance Remove Custom NavBar Background for UIPopoverController but it did not work. The code I used was:

[[UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];

But it had no effect whatsoever. My app is iOS 6+. Is this something specific to MFMailComposeViewController or am I missing something from this?

Edit: other approaches attempted:

MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
mailer.navigationBar.barStyle = UIBarStyleBlack;
[self.navigationController presentViewController:mailer animated:YES completion:nil];
[mailer.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];

Setting UIBarStyleBlack has some effect as the "Cancel" button subsequently turns black, but the background image is still set at the old value.

Broadtail answered 26/2, 2013 at 20:16 Comment(5)
Looks like the only way out is simply not to use UIAppearance but set the image on those navigation controllers that need it individually.Broadtail
Did you have any luck figuring out how to do this with UIAppearance?Tala
No, the only working solution was to stop using UIAppearance and just set the desired style to each navbar individually.Broadtail
i am facing also this issue for ios7.0. did you find any solution for that?Tiphane
The only solution I found was to stop using UIAppearance altogether.Broadtail
C
0

Try something like this:

MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
[mail.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];

This should reset the background image for just this instance.

Cotemporary answered 26/2, 2013 at 20:23 Comment(2)
Tried this one too, did not have any effect, unfortunately.Broadtail
Try setting the background image after you make the call to display the mail compose controller.Cotemporary
P
0

Remove custom background image

[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];

BEFORE calling,

MFMailComposeViewController *vc = [[MFMailComposeViewController alloc] init];

Point is to set any customization for Navigation Bar appearance before init.

Posen answered 3/8, 2014 at 5:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.