Mi Ch Mi Ch - 1 year ago 93
Swift Question

Animation on button image when tapped

I'm new to Swift and to stackoverflow so please comment for any improvements. I can make to my asking of questions!

I have created a

that has an image. When tapped, the image is supposed to change to another image. Currently, once tapped, it 'flashes' with the image it is supposed to change to and then immediately changes back to the original image.

I created an outlet:

@IBOutlet var buttonImage: UIButton!

Then I added this:

override func viewDidLoad() {
//Change image.



Help is gratefully received.

EDIT - added error screenshot.errorscreenshot

Answer Source

You need to change your viewDidLoad code like this


Now change you IBAction like this

@IBAction func btnTap(sender: UIButton) {
    sender.selected = !sender.selected

Hope this will help you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download