UIBarButtonItem appearance setTitleTextAttributes does not affects UIControlStateDisabled state
Asked Answered
C

2

16

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?

Contaminant answered 30/7, 2012 at 8:59 Comment(1)
For 6.0 and later use NSForegroundColorAttributeName instead of UITextAttributeTextColorAfb
B
29

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.)

Blakley answered 16/11, 2012 at 17:2 Comment(1)
Amazing. How would anyone ever know that!Stowaway
L
0

It's working fine for me with iOS 5.1. Perhaps it was a 5.0 bug.

Larocca answered 31/8, 2012 at 22:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.