Swift… how can I make an image change when a butto

2019-08-14 04:25发布

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条回答
【Aperson】
2楼-- · 2019-08-14 05:02

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)
查看更多
登录 后发表回答