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

soh*_*_ju 7 uibutton ios4 ios

如何在点击事件中更改我的UIButton的背景图像?并使用上一张图片在几秒钟内刷新它?我的意思是在点击时更改它的背景图像并在点击后重置它.

Kri*_*dra 13

[yourButton setImage:[UIImage imageNamed:@"yourNormalImage.png"] forState:UIControlStateNormal];
[yourButton setImage:[UIImage imageNamed:@"yourImageWhenClicking.png"] forState:UIControlStateHighlighted];
Run Code Online (Sandbox Code Playgroud)

将您的clickEvent图像作为按钮的突出显示图像.


The*_*Fox 6

以上答案不起作用,因为它不会改变背景而是UIButton改变背景图像的侧面图像:

[yourButton setBackgroundImage:[UIImage imageNamed:@"yourimage"] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)