Animating UIButton Images

I would like to give a UIButton in my application a continuous "ripple" effect as it animates a series of images and then reverts back through those same images. I found examples of UIImageViews using the animationImages property, but all I found for UIButtons is animation changing their alpha.

UIView's setAnimationRepeatAutoreverses method is what I want for a loop, but I don't understand how to use an array of images in an animation block for a UIButton. Is this possible or is the NSTimer / setImage approach recommended? Any examples are greatly appreciated.

+2


source to share


2 answers


You can add UIImageView as a subarea of ​​your button and use the animationImages property. If you want to use your backgroundImage UIButton property, you can try to find the corresponding UIImageView as a child of the UIButton and apply the same animationImages method.



+1


source


While the subview method works, the easiest is to simply set the animationImages property on the UVIutton of the imageView. From the docs:

Although the [imageView] property is read-only, its own properties are read / written. using these properties to customize the appearance and browsing behavior of buttons.



For example:

self.pulsingButton.imageView.animationImages =
    [NSArray arrayWithObjects:[UIImage imageNamed:@"button1.png"],
                              [UIImage imageNamed:@"button2.png"],
                              nil];

      

+6


source







All Articles