Swift… how can I make an image change when a button its pressed and return it back to normal?

不打扰是莪最后的温柔 提交于 2019-12-11 13:11:22

问题


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.


回答1:


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)


来源:https://stackoverflow.com/questions/28320597/swift-how-can-i-make-an-image-change-when-a-button-its-pressed-and-return-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!