Ios5 -[[UIButton外观]setBackgroundImage]为什么会影响UIBarItem对象的初始外观?如何更正它?

Ios5 -[[UIButton外观]setBackgroundImage]为什么会影响UIBarItem对象的初始外观?如何更正它?,ios5,uikit,appearance,Ios5,Uikit,Appearance,当使用类代理自定义UIButton的外观时,UIBarItems最初似乎采用为UIButton设置的自定义属性 从使用核心数据的默认主/详细项目开始。自定义AppDelegate中UIButton的外观并运行应用程序。单击MasterViewController导航栏中的“编辑”按钮,然后单击“完成”按钮,然后观察自定义消失 [AppDelegate应用程序:didFinishLaunchingWithOptions]中的自定义外观代码: UIImage *customBackground =

当使用类代理自定义UIButton的外观时,UIBarItems最初似乎采用为UIButton设置的自定义属性

从使用核心数据的默认主/详细项目开始。自定义AppDelegate中UIButton的外观并运行应用程序。单击MasterViewController导航栏中的“编辑”按钮,然后单击“完成”按钮,然后观察自定义消失

[AppDelegate应用程序:didFinishLaunchingWithOptions]中的自定义外观代码:

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

所有UIBarButtonims都使用自定义背景进行初始化


当“编辑”按钮被“完成”按钮替换时,它正确地没有自定义背景

。我很关心为什么UIBarItem对象会发生这种情况,因为它们不是从UIButton继承的,我想知道如何更正它


我怀疑代理继承和支持的属性,但我不知道如何更正它。有什么建议吗?

我的建议是当包含在
UINavigationBar
中时,将
backgroundImage
重置为
nil

[[UIButton appearance] setBackgroundImage:customBackground forState:UIControlStateNormal];
[[UIButton appearanceWhenContainedIn:[UINavigationBar class], nil] setBackgroundImage:nil forState:UIControlStateNormal];

我遇到了同样的问题,还没有找到一个很好的解决方案。我目前正在使用“[UIButton Appearance When contained:”来修复此错误。我对此并不满意,因此我很想听听其他人是否有更好的解决方案。