【问题标题】:UIBarButtonItem appearance setTitleTextAttributes does not affects UIControlStateDisabled stateUIBarButtonItem 外观 setTitleTextAttributes 不影响 UIControlStateDisabled 状态
【发布时间】: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


【解决方案1】:

您必须为控制状态 Normal 和 Disabled 设置它。

(2015-11-18 -- 从 iOS 9.1 开始,您仍然必须同时设置两者。)

【讨论】:

  • 太棒了。怎么会有人知道!
【解决方案2】:

iOS 5.1 对我来说运行良好。可能是 5.0 的错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 2018-10-12
    • 2012-09-30
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 2021-06-04
    相关资源
    最近更新 更多