Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - UIButton - background image for disabled

I have UIButton that I set the background image for three states, normal, highlighted, and disabled, all with the following format:

[button setBackgroundImage:buttonBGD forState:UIControlStateDisabled];

My problem is, that when the button is disabled, the iPhone chooses to lighten the image for me. Which isn't desired. But if I tell it:

[button setAdjustsImageWhenDisabled:NO];

Then the image doesn't change at all. How do I remove the automatic lightening of the image, and instead use just the original image I created?

like image 813
RyanJM Avatar asked Nov 03 '10 21:11

RyanJM


1 Answers

Try:

[button setBackgroundImage:buttonBGD forState:UIControlStateNormal | UIControlStateDisabled]

If you want the same disabled image when the button is selected and disabled, then add:

[button setBackgroundImage:buttonBGD forState:UIControlStateSelected | UIControlStateDisabled];

Hope that helps!

like image 110
Quentin Avatar answered Nov 08 '22 16:11

Quentin