How to set disabled system button's tint color applied to its image

Viewed 632

If you create a UIButton and provide an image for it, like so

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; [button setImage:[UIImage imageNamed:@"share"] forState:UIControlStateNormal];

the button's image will appear tinted as expected.

enter image description here

When you set enabled to NO it is automatically tinted light gray:

enter image description here

The question is, how do you change the tint color applied when the button is disabled? Instead of that default light gray color, I'd like to apply a different gray color.

I know that if the button had text instead of an image, you could change the text color for the disabled state via [button setTitleColor:[UIColor darkGrayColor] forState:UIControlStateDisabled]; but since there is no title, just an image, I don't see any way to use a custom tint color for the disabled state.

I also know that if you use UIButtonTypeCustom you can provide different images for different states including disabled. The problem with this is the button tint does not dim when it is supposed to, for example, when an alert is presented it is not colored light gray to indicate you can't interact with this element until the alert is dismissed. There's also no animations between states, for example when highlighted the image immediately changes instead of the nice fade effect system buttons provide. That's not acceptable to me.

0 Answers
Related