I have two PNGs I want to use as a button. How can I animate a UIButton by switching rapidly between these two images?
Normally for a button you can set three "live" states: - Normal - Highlighted - Selected I don't know if this can help, but if you set one image to "Normal" and the other image to "Highlighted" you can see the two images while pushing the button. I don't know if this effect is enough for you.
You can use animationImages
property of your button's imageView
:
myButton.imageView.animationImages =
[NSArray arrayWithObjects:[UIImage imageNamed:@"image1.png"],
[UIImage imageNamed:@"image2.png"],
nil];
myButton.imageView.animationDuration = 0.5; //whatever you want (in seconds)
[myButton.imageView startAnimating];
Your button will switch between your two images.
EDIT: As @tidbeck pointed the button needs to have an image assigned to create the imageview
property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With