UIAppearance Remove Custom NavBar Background for UIPopoverController

北战南征 提交于 2019-12-19 02:52:16

问题


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:

How I want it to look like:

Thanks in advance for your help, Guvvy


回答1:


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:.



来源:https://stackoverflow.com/questions/11334062/uiappearance-remove-custom-navbar-background-for-uipopovercontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!