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

2019-08-14 04:21发布

问题:

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)