Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIAppearance Remove Custom NavBar Background for UIPopoverController

I'm in the process of incorporating iOS 5's UIAppearance feature to give my universal app a unique theme. Currently, I have implemented some code in my App Delegate to give the app custom navigation bars:

UIImage *navBarImage = [[UIImage imageNamed:@"navigationBar.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(7, 7, 7, 7)];
[[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault];

This works well and changes all the navigation bars from Apple's plain style to a bright gradient. However, the problem I am having is that it is overriding some style that I don't want it too. My particular issue is that it overrides the navigation bar background in the iPad's UIPopoverController, creating an ugly user experience. Please tell me how to fix it.

Edit: Please note that this is an universal app and I open the image picker through a UIPopoverController on the iPad and a modal view on the iPhone/iPod. I only want to remove the custom background for the navBar on the iPad popover, not on the modal view.

How it currently looks like: enter image description here

How I want it to look like: enter image description here

Thanks in advance for your help, Guvvy

like image 712
Gavy Avatar asked Jul 04 '12 18:07

Gavy


1 Answers

Try using the +appearanceWhenContainedIn: method to remove your background-image customization from navigation bars when they’re contained in popover controllers. Something like this:

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

It’s not clear from the documentation whether setting a navigation bar’s background image to nil restores its default appearance—if that doesn’t work, you might have to take the opposite approach, and provide the list of non-popover container view controllers you’re using to +appearanceWhenContainedIn:.

like image 164
Noah Witherspoon Avatar answered Sep 28 '22 08:09

Noah Witherspoon