Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton Background image Change programmatically

Tags:

ios

uibutton

ios4

How can I change the background image of my UIButton in click event? And refresh it in a few second with the previous image? I mean change it's background image on click and reset it after the click.

like image 790
sohel14_cse_ju Avatar asked Apr 27 '11 08:04

sohel14_cse_ju


2 Answers

[yourButton setImage:[UIImage imageNamed:@"yourNormalImage.png"] forState:UIControlStateNormal];
[yourButton setImage:[UIImage imageNamed:@"yourImageWhenClicking.png"] forState:UIControlStateHighlighted];

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

like image 182
Krishnabhadra Avatar answered Nov 19 '22 09:11

Krishnabhadra


The above answer is not working because it doesn't change the background but the side image of the UIButton, to change the background image use:

[yourButton setBackgroundImage:[UIImage imageNamed:@"yourimage"] forState:UIControlStateNormal];
like image 6
MineConsulting SRL Avatar answered Nov 19 '22 10:11

MineConsulting SRL