简体   繁体   中英

UIButton Background image Change programmatically

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.

[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..

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM