为什么 - [[UIButton appearance] setBackgroundImage]会影响UIBarItem对象的初始外观以及如何更正它? [英] Why does -[[UIButton appearance] setBackgroundImage] affect the initial appearance of UIBarItem objects and how do you correct it?

查看:229
本文介绍了为什么 - [[UIButton appearance] setBackgroundImage]会影响UIBarItem对象的初始外观以及如何更正它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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.

[AppDelegate application:didFinishLaunchingWithOptions]中的自定义外观代码:

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];  



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



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

类似的问题询问如何自定义完成按钮。我担心为什么会发生UIBarItem对象,它不会从UIButton继承,并且想知道如何纠正它。

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?

推荐答案

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

My suggestion would be to reset backgroundImage to nil when contained in UINavigationBar:

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

这篇关于为什么 - [[UIButton appearance] setBackgroundImage]会影响UIBarItem对象的初始外观以及如何更正它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆