UIBarButtonItem外观setTitleTextAttributes不影响UIControlStateDisabled状态

laz*_*rev 16 appearance uibarbuttonitem uibarbuttonitemstyle ios5

我们的设计师让我为禁用的UIBarButtonItems文本使用特定颜色.我用来实现这个代码:

NSDictionary* textAttributes = [NSDictionary dictionaryWithObject: [UIColor blueColor]
                                                           forKey: UITextAttributeTextColor];

[[UIBarButtonItem appearance] setTitleTextAttributes: textAttributes
                                            forState: UIControlStateDisabled];
Run Code Online (Sandbox Code Playgroud)

但它没有改变文本属性.

我已尝试使用Normal状态的代码,尝试使用setBackgroundImage为UIControlStateDisabled按钮添加背景,并且所有thouse实验都能正常工作.但是这个单一的组合:setTitleTextAttributes和UIControlStateDisabled没有做任何事情.

谷歌没有给我任何关于这个特定组合的相关答案.

有没有人知道改变禁用的UIBarButtonItem的颜色的其他方法或使setTitleTextAttributes适用于diabled项目的方法?

Καr*_*hικ 29

您必须将其设置为控制状态Normal和Disabled.

(2015-11-18 - 从iOS 9.1开始,你必须同时设置它们.)

  • 惊人.怎么会有人知道这一点! (2认同)