如何更改在 Xcode 界面生成器中创建的按钮上的图像?
使用 xcode 我创建了一个带有多个按钮的界面,我遇到的问题是我想在单击按钮后更改按钮上的图像。我知道如果我以编程方式创建按钮,但不知道如何更改在界面生成器中创建的图像,我将如何执行此操作。
我真的不想从头开始并以编程方式再次构建界面,所以 如果有人能指出我正确的方向,我将不胜感激。
谢谢。
Using xcode I have created an interface with several buttons, the problem I am having is that I would like to change the image on a button once it has been clicked. I understand how I would do this if I created the button programatically but no idea how to change an image that was created in the interface builder.
I don't really want to start from scratch and build the interface again programmatically so
if anyone could point me in the right direction I would appreciate it.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用按钮图像属性:
您需要建立到
UIButton
的IBOutlet
连接。Use the button image property:
You will need to have established an
IBOutlet
connection to theUIButton
.确保您的类具有相应的按钮
UIButton
属性:然后在用户界面构建器中您可以连接按钮和插座。
然后,您可以在代码中访问按钮属性,就像以编程方式创建按钮一样。
Make sure your class has a corresponding
UIButton
property for the button:Then in the User Interface builder you can connect the button and the outlet.
In your code you can then access the button properties like you created it programatically.