我们的设计师要求我为禁用的 UIBarButtonItems 的文本使用特定颜色。我用来实现这个的代码:
NSDictionary* textAttributes = [NSDictionary dictionaryWithObject: [UIColor blueColor]
forKey: UITextAttributeTextColor];
[[UIBarButtonItem appearance] setTitleTextAttributes: textAttributes
forState: UIControlStateDisabled];
但它不会改变文本属性。
我已经在 Normal 状态下尝试过这段代码,尝试使用 setBackgroundImage 更改 UIControlStateDisabled 按钮的背景,并且所有 thouse 实验都运行良好。但是这个单一的组合:setTitleTextAttributes 和 UIControlStateDisabled 没有任何作用。
谷歌没有给我任何关于该特定组合的相关答案。
有人知道改变禁用 UIBarButtonItem 颜色的其他方法或使 setTitleTextAttributes 适用于禁用项目的方法吗?
最佳答案
您必须为控制状态 Normal 和 Disabled 设置它。
(2015 年 11 月 18 日——从 iOS 9.1 开始,您仍然必须同时设置两者。)
关于ios5 - UIBarButtonItem 外观 setTitleTextAttributes 不影响 UIControlStateDisabled 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11718243/