UIButton Background Image Change Programmatically

How to change the background image of my UIButton in a click event? And update it after a few seconds with the previous image? I mean change its background image to click and reset after click.

+7
source share
2 answers
[yourButton setImage:[UIImage imageNamed:@"yourNormalImage.png"] forState:UIControlStateNormal]; [yourButton setImage:[UIImage imageNamed:@"yourImageWhenClicking.png"] forState:UIControlStateHighlighted]; 

put the clickEvent image as the highlighted image of your button.

+13
source

This answer does not work, because it does not change the background, but a side UIButton image, to change the use of the background image:

 [yourButton setBackgroundImage:[UIImage imageNamed:@"yourimage"] forState:UIControlStateNormal]; 
+6
source

All Articles