7

When customizing the appearance of UIButton using the class proxy UIBarItems seem to initially take on the custom properties set for UIButton.

Starting with the default Master/Detail project using Core Data. Customize the appearance of UIButton in the AppDelegate and run the app. Click the Edit button, then the Done button in the navigation bar for the MasterViewController and watch the customization go away.

Custom appearance code in [AppDelegate application:didFinishLaunchingWithOptions]:

UIImage *customBackground = [[UIImage imageNamed:@"yourcustomimage.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(5,5,5,5)];  
[[UIButton appearance] setBackgroundImage:customBackground forState:UIControlStateNormal];  

All UIBarButtonItems initialize with custom background.
All UIBarButtonItems initialize with custom background

When the Edit button is replaced by the Done button, it correctly does not have the customized background.
When the Edit button is replaced by the Done button, it correctly does not have the customized background.

A similar question asks how to customize the Done button. I'm concerned why this is happening at all to UIBarItem objects, which do not inherit from UIButton, and would like to know how to correct it.

I suspect the proxy inheritance and the supported properties, but I don't know how to correct for it. Any suggestions?

4

1 回答 1

1

我的建议是重置backgroundImagenil包含在UINavigationBar

[[UIButton appearance] setBackgroundImage:customBackground forState:UIControlStateNormal];
[[UIButton appearanceWhenContainedIn:[UINavigationBar class], nil] setBackgroundImage:nil forState:UIControlStateNormal];
于 2013-04-13T17:59:04.540 回答