【发布时间】:2017-05-26 18:29:33
【问题描述】:
我有一个 UIColor 的扩展来从十六进制字符串中获取颜色。我按照以下方式使用它:
self.navigationItem.rightBarButtonItem?.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor(hexString: "#C0BFC0")], for: UIControlState.disabled)
self.navigationItem.rightBarButtonItem?.isEnabled = false
由于某种奇怪的原因,rightBarButtonItem 的颜色与以前相同。有没有办法在禁用时更改它?我的 viewDidLoad 函数中有以上内容
我尝试阅读以下内容:
UIBarButtonItem is disabled, but has normal color
Change color of disabled bar button item in iOS
当它未被禁用时,我可以更改颜色。似乎当它被禁用时,颜色不被遵守?
【问题讨论】:
-
我也遇到了这个错误,它似乎只发生在 Swift 或最近的 iOS 版本中。我的解决方法是使用常规 UIButton 并将 UIBarButtonItem 用作自定义视图。 UIButton可以正常修改。
标签: uibarbuttonitem