如何在按钮中设置图像

发布于 2024-09-09 05:29:48 字数 88 浏览 0 评论 0原文

单击按钮图像时如何在按钮中设置图像向我显示该按钮 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

牵强ㄟ 2024-09-16 05:29:48

在当前触摸按钮时为按钮设置图像(我认为这就是您所要求的)。您可以在 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'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文