1
我有一个扩展UIColor从十六进制字符串中获取颜色。我用它作为每如下:禁用时设置UIBarButtonItem灰色
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
我能够改变颜色,当它没有被禁用。似乎什么时候禁用颜色不服从?
我遇到这个错误太,它似乎只与斯威夫特也许最近的iOS版本的发生。我的解决方法是使用常规的UIButton,并将UIBarButtonItem作为自定义视图进行初始化。 UIButton可以正常修改。 – Siegfoult