【发布时间】:2012-07-27 22:17:27
【问题描述】:
我们的设计师要求我为禁用的 UIBarButtonItems 的文本使用特定颜色。我用来实现这个的代码:
NSDictionary* textAttributes = [NSDictionary dictionaryWithObject: [UIColor blueColor]
forKey: UITextAttributeTextColor];
[[UIBarButtonItem appearance] setTitleTextAttributes: textAttributes
forState: UIControlStateDisabled];
但它不会改变文本属性。
我已经尝试使用正常状态的代码,尝试使用 setBackgroundImage 更改 UIControlStateDisabled 按钮的背景,并且所有 thouse 实验都运行良好。但是这个单一的组合:setTitleTextAttributes 和 UIControlStateDisabled 没有任何作用。
Google 没有就该特定组合给我任何相关答案。
有没有人知道改变禁用 UIBarButtonItem 的颜色的其他方法或使 setTitleTextAttributes 对禁用项目起作用的方法?
【问题讨论】:
-
对于 6.0 及更高版本,使用 NSForegroundColorAttributeName 而不是 UITextAttributeTextColor
标签: ios5 uibarbuttonitem appearance uibarbuttonitemstyle