Eduardo Benitez Eduardo Benitez - 2 months ago 5
Swift Question

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

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.

Answer

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)