Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable the highlight control state of a UIButton?

Your button must have its buttonType set to Custom.

In IB you can uncheck "Highlight adjusts image".

Programmatically you can use theButton.adjustsImageWhenHighlighted = NO;

Similar options are available for the "disabled" state as well.


In addition to above answer of unchecking "highlight adjusts image" in IB, make sure that button type is set CUSTOM.


This will work for you:

[button setBackgroundImage:[UIImage imageNamed:@"button_image"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"button_image_selected"] forState:UIControlStateSelected];
[button setBackgroundImage:[UIImage imageNamed:@"button_image_selected"] forState:UIControlStateSelected | UIControlStateHighlighted];

3rd line is the trick here...

This works the same for setting image/backgroundImage


adjustsImageWhenHighlighted = NO;

button.adjustsImageWhenDisabled = NO;

is equally useful for having your own appearance of a disabled button.