Dylan Hawley
Dylan Hawley

Reputation: 55

Xcode (Swift) - How to store name of image file on button

I am trying to get the name for the image file on a UIButton. I set the image using

buttonName.setImage(UIImage(named:"BluePiece.png"), forState: .Normal)
buttonName.setImage(UIImage(named:"RedPiece.png"), forState: .Normal)

and I want to be able to compare the NAMES of the image files in an "if statement". Also, I am using swift and Xcode 6.4.

Upvotes: 1

Views: 1574

Answers (1)

Ashish Kakkad
Ashish Kakkad

Reputation: 23882

Complare images :

if(btn.imageView.image == UIImage(named:"BluePiece.png")){
    //do your stuff here
}

Or you can take one Boolean variable - set true or false by changing and comparing the images.

Upvotes: 1

Related Questions