I'm setting an image for my navigationbar like so:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault];
Then I don't want this image for classes of MFMessageComposeViewController
so I exclude it by doing this:
[[UINavigationBar appearanceWhenContainedIn:[MFMessageComposeViewController class], nil] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
But it has no effect (the navbar is still styled with my image inside the MFMessageComposeViewController
). What am I missing here?
Found out the solution to my problem:
Subclass the MFMessageComposeViewController
In the init method set the backgroundImage
of the navigationBar
to nil
Voilá!
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
[self.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
}
return self;
}
Just before presenting the MFMessageComposeViewController try
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"MyUINavigationBarImageClear"] forBarMetrics:UIBarMetricsDefault];
and in the messageComposeViewController:didFinishWithResult: callback reset to
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"MyUINavigationBarImageFull"] forBarMetrics:UIBarMetricsDefault];
I'm also setting the .navigationBar.tintColor property of the MFMessageComposeViewController to get the cancel button to match my MyUINavigationBarImageClear image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With