UIBarButtonItem is disabled, but has normal color

前端 未结 6 1181
失恋的感觉
失恋的感觉 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 19:45

    You have likely set the bar button item title text attributes for the .Normal state and need to also set it for the .Disabled state.

    There are two ways to fix this, one if you are setting the title text attributes on the bar button item instance and in the other case if you use the appearance proxy.

    Single instance:

    saveButton.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.grayColor()], forState: .Disabled)
    

    Appearance proxy:

    UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([MyNavigationController.self]).setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.grayColor()], forState: .Disabled)
    

提交回复
热议问题