我正在使用外观代理来设计我的应用程序的样式,但是我的UIBarButtonItem外观有问题;我想只设置顶部UINavigationbar的按钮的样式,但是当我运行下面的代码时,同样的样式也应用于键盘的done按钮。
NSDictionary *btnAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor blackColor],
UITextAttributeTextColor,
[UIColor clearColor],
UITextAttributeTextShadowColor, nil];
[[UIBarButtonItem appearance] setTitleTextAttributes: btnAttributes
forState: UIControlStateNormal];
所以,我的问题是:是否有可能-使用外观代理-仅设置顶部导航栏的栏按钮的样式?
发布于 2013-03-10 05:41:57
您可以将外观限制为某些容器类。从appearance reference
appearanceWhenContainedIn:
返回给定包含层次结构中接收方的外观代理。(必填)
+ (id)appearanceWhenContainedIn:(Class <UIAppearanceContainer>)ContainerClass,...
Parameters ContainerClass,一个以nil结尾的外观容器类列表。返回值给定容器层次结构中接收方的外观代理。
类讨论此方法对不是符合UIAppearanceContainer协议的对象的var-args列表中的任何项抛出异常。
可用性在iOS 5.0及更高版本中可用。
对于您的示例,这将是:
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationController class], nil]
setTitleTextAttributes:btnAttributes
forState:UIControlStateNormal];
https://stackoverflow.com/questions/15316071
复制相似问题