简体   繁体   English

UIButton 背景图像 以编程方式更改

[英]UIButton Background image Change programmatically

How can I change the background image of my UIButton in click event?如何在点击事件中更改 UIButton 的背景图片? 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..将您的 clickEvent 图像作为按钮的突出显示图像..

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:上面的答案不起作用,因为它不会更改背景,而是更改UIButton的侧面图像,以更改背景图像使用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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