UIButton: set image for selected-highlighted state
I set an images for button's states Normal,Highlighted and Selected, but when the button in selected state and I press/highlight it I didn't see my highlighted image but just grayed picture. Is it possible to set an image for highlighted state when the button selected?
my code:
[button setImage:[UIImage imageNamed:@"normal.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"pressed.png"] forState:UIControlStateHighlighted];
[button setImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateSelected];
when I do:
[button setSelected:YES];
and press the button, the "pressed.png" image doesn't select.
I found the solution: need to add addition line
[button setImage:[UIImage imageNamed:@"pressed.png"] forState:UIControlStateSelected | UIControlStateHighlighted];
You can do this in Interface Builder.
Select the UIButton
you wish to set in IB
then go to the attributes inspector
.
In the screen shots,I am using a custom button type , but that does not matter.