Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

animate uibutton applying images swift

I want to apply animation effect by changing two images on button turn by turn. I have applied following code but not able to see animation effect. I have applied IBOutlets properly.

    var image1:UIImage = UIImage(named: "img_mic_off")!
    var image2:UIImage = UIImage(named: "img_mic_on")!
    btnRecord.imageView?.animationImages = [image1,image1]
    btnRecord.imageView?.animationDuration = 1.0
    btnRecord.imageView!.startAnimating()

Please help me to resolve issue that why it is not working with this given code. Thanks in advance.

like image 688
Zalak Patel Avatar asked Jan 08 '23 10:01

Zalak Patel


1 Answers

Check out what I've done. The images are changing. So I hope this is what you actually needed.

var image1:UIImage = UIImage(named: "img_mic_off")!
var image2:UIImage = UIImage(named: "img_mic_on")!
btn.setImage(image1, forState: UIControlState.Normal)
btn.imageView!.animationImages = [image1, image2]
btn.imageView!.animationDuration = 1.0
btn.imageView!.startAnimating()
like image 95
Vasil Garov Avatar answered Jan 10 '23 23:01

Vasil Garov