如何在按钮中设置图像
单击按钮图像时如何在按钮中设置图像向我显示该按钮 run.backgroundColor = [UIColor redColor] 我尝试了这个,但它不起作用,
How set image in button when ever click the button image show me that button
run.backgroundColor = [UIColor redColor] I try this but it doesn't work,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在当前触摸按钮时为按钮设置图像(我认为这就是您所要求的)。您可以在 UIButton 上使用 setImage: forState。
[myButton setImage:[UIImage imageNamed:@"myButtonGraphic.png"] forState:UIControlStateHighlighted];
您可以使用不同的控件状态来控制图像何时显示,其中之一是:
UIControlStateNormal
UIControlStateHighlighted
UIControlStateDisabled
UIControlStateSelected
UIControlStateApplication
UIControlStateReserved
If您使用 UIControlStateNormal,图像始终显示,当当前触摸按钮时,它会显得更暗,这在很多情况下足以向用户表明他们正在选择该按钮并且它是真正可触摸的'事物'。
To set an image for a button while it is currently being touched (I think this is what you're asking). You use setImage: forState on the UIButton.
[myButton setImage:[UIImage imageNamed:@"myButtonGraphic.png"] forState:UIControlStateHighlighted];
You can control when the image appears using the different control states, one of:
UIControlStateNormal
UIControlStateHighlighted
UIControlStateDisabled
UIControlStateSelected
UIControlStateApplication
UIControlStateReserved
If you use UIControlStateNormal, the image is displayed all the time, and when the button is currently being touched it will appear dimmer which for a lot of cases is good enough to indicate to the user that they are selecting that button and that it's a real touchable 'thing'.