UIButton that cycles through images when clicked
Posted
by dot
on Stack Overflow
See other posts from Stack Overflow
or by dot
Published on 2010-03-23T02:04:06Z
Indexed on
2010/03/23
2:11 UTC
Read the original article
Hit count: 347
iphone
|iphone-sdk
I have three images that I want to cycle through when clicking on a UIButton.
How would I go about doing this?
This is what I have so far, but it's not really working.
//the images
NSString* imageNames[] = {"MyFirstImage", "AnotherImage", whatever else};
int currentImageIndex = 0;
and
- (IBAction)change{
UIImage* imageToShow = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource: imageNames[currentImageIndex] ofType:@"png"];
if( currentImageIndex++ == sizeof(imageNames)/sizeof(NSString)) //check to see if you hit the last image
{
currentImageIndex = 0; //start over
}
}
Ideas?
Any help will be greatly appreciated! Thanks!
© Stack Overflow or respective owner