Search code examples
ios5uibarbuttonitemappearanceuibarbuttonitemstyle

UIBarButtonItem appearance setTitleTextAttributes does not affects UIControlStateDisabled state


Our designer asked me to use specific color for text of disabled UIBarButtonItems. That code I've used to implement this:

NSDictionary* textAttributes = [NSDictionary dictionaryWithObject: [UIColor blueColor]
                                                           forKey: UITextAttributeTextColor];

[[UIBarButtonItem appearance] setTitleTextAttributes: textAttributes
                                            forState: UIControlStateDisabled];

But it doesn't changed text attributes.

I've tried this code with Normal state, tried to chage background for UIControlStateDisabled buttons with setBackgroundImage and all thouse experiments works perfectly. But this single combination: setTitleTextAttributes and UIControlStateDisabled doesn't do anything.

Google didn't give me any relevant answer about that specific combination.

Does anybody know other way to change color of disabled UIBarButtonItem or way to make setTitleTextAttributes work for diabled items?


Solution

  • You have to set it for both control state Normal and Disabled.

    (2015-11-18 -- As of iOS 9.1 you must still set both.)