Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Image clicked Button not changing

Tags:

ios

swift

I have a button which is supposed to change image when it is clicked but for some reason it is not changing to the image set for the UIControlState.Highlighted state

 override func viewDidLoad() {
    super.viewDidLoad()
    let versusButtonClickedImage = UIImage(named: "versus_button_cicked") as UIImage
    let versusButtonImage = UIImage(named: "versus_button") as UIImage
    versusButton.setImage( versusButtonImage, forState: UIControlState.Normal)


    versusButton.setImage(versusButtonClickedImage, forState: UIControlState.Highlighted)


}
like image 822
user3871362 Avatar asked Dec 20 '22 12:12

user3871362


1 Answers

You have to add extension of image.
And no need to create separate variables of image.

testBtn.setImage(UIImage(named:"a1.png"),forState:UIControlState.Normal)
testBtn.setImage(UIImage(named:"a2.png"),forState:UIControlState.Highlighted)
like image 61
Ashish Kakkad Avatar answered Dec 31 '22 00:12

Ashish Kakkad