Swift ...当按下按钮并将其恢复正常时,如何更改图像? [英] Swift... how can I make an image change when a button its pressed and return it back to normal?

查看:161
本文介绍了Swift ...当按下按钮并将其恢复正常时,如何更改图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Swift ...当按下按钮时如何更改图像并在手指不再触摸按钮时将其恢复正常?



<我试图通过制作一个简单的应用程序来学习swift,但我坚持制作一个简单的按钮,在按下时更改属性。现在我可以在点击时更改它,并在再次触摸时恢复正常。

解决方案

你可以改变通过设置指定状态的图像来按钮图像。在您的情况下,您必须将其设置为高亮状态

  button.setImage(UIImage(名称:highlighted_image),forState: .Highlighted)


Swift... how can I make an image change when a button its pressed and return it back to normal as soon as the finger is not longer touching the button?

Im trying to learn swift by making a simple app but Im stuck in making a simple button that changes properties just when it is being pressed. For now I can just make it change when it is clicked and get back to normal when its touched again.

解决方案

You can change button images by setting image for specified state. In your case you have to set it for state highlithed

button.setImage(UIImage(named: "highlighted_image"), forState:.Highlighted)

这篇关于Swift ...当按下按钮并将其恢复正常时,如何更改图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆