Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS – UIAppearance appearanceWhenContainedIn issues

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?

like image 945
Peter Warbo Avatar asked Aug 18 '12 09:08

Peter Warbo


2 Answers

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;
}
like image 123
Peter Warbo Avatar answered Oct 04 '22 13:10

Peter Warbo


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.

like image 37
user1195883 Avatar answered Oct 04 '22 13:10

user1195883