UIBarButtonItem is disabled, but has normal color

前端 未结 6 1239
失恋的感觉
失恋的感觉 2021-02-12 19:25

I\'m having an issue with a UIBarButtonItem. I use the appearance proxy to set its color for states Normal and Disabled and I do this in t

6条回答
  •  难免孤独
    2021-02-12 20:05

    This updates the answer for Swift 4.0:

    barButtonItem.setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.gray], for: UIControlState.disabled)
    

    This shows an illustrative example of an orange color for disabled against a white barTintColor:

    barTintColor = .white    
    cancelButton.isEnabled = false
    cancelButton.setTitleTextAttributes(
        [NSAttributedStringKey.foregroundColor: UIColor.orange], 
        for: UIControlState.disabled)
    

提交回复
热议问题