Reputation: 55
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
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