Hi, I'm trying to create a button which displays animated images. I read in this post the suggestion that I add an UIImageView (with an array of animationImages) as a subview of the UIButton. I tried to do this like so: (animation1 is a UIImageView object declared in the header)
- (void)viewDidLoad {
UIImage *image1 = [UIImage imageNamed:@"Good1.png"];
UIImage *image2 = [UIImage imageNamed:@"Good2.png"];
UIImage *image3 = [UIImage imageNamed:@"Bad1.png"];
NSArray *images = [[NSArray alloc] initWithObjects:image1, image2, image3, nil];
animation1.animationImages = images;
[images release];
[self.button1 addSubview:animation1];
[self.button1 bringSubviewToFront:animation1];
[button1 setNeedsDisplay];
animation1.animationDuration = 1;
animation1.animationRepeatCount = 3;
[animation1 startAnimating];
[super viewDidLoad];
}
But nothing appears within the button. Any ideas where I might be going wrong?
Also, I would like it so that different methods are called depending on which image is showing when the user presses the button. I achieved this previously but creating an array of images, using an NSTimer to set the background image of the UIButton to cycle to through these images, and then comparing the image data of the button when pressed to the images in the array, calling a different method for each. This really doesn't seem very efficient! Hence why I'm trying to cycle the images in a subview. Any suggestions of how I might extract imagedata from the UIImageView subview of the UIButton when the button is pressed would be most appreciated :)
Thanks!
Michael