user2012821
user2012821

Reputation: 41

iOS: UIImageView Slideshow

For an iOS app, I would like a UIImageView to have multiple images in a slideshow. I also want to be able to select the active photo on-the-fly. Is there an easy way to do this? (Specific code would be nice, but a hint or two would also be appreciated).

Thanks!

Upvotes: 2

Views: 3941

Answers (2)

Alexis C.
Alexis C.

Reputation: 4918

I made a small library for this purpose, very flexible with tons of options : https://github.com/kirualex/KASlideShow

A simple slideshow declaration looks like this :

_slideshow.delegate = self;
[_slideshow setDelay:1]; // Delay between transitions
[_slideshow setTransitionDuration:.5]; // Transition duration
[_slideshow setTransitionType:KASlideShowTransitionFade]; // Choose a transition type (fade or slide)
[_slideshow setImagesContentMode:UIViewContentModeScaleAspectFill]; // Choose a content mode for images to display
[_slideshow addImagesFromResources:@[@"test_1.jpeg",@"test_2.jpeg",@"test_3.jpeg"]]; // Add images from resources
[_slideshow addGesture:KASlideShowGestureTap]; // Gesture to go previous/next directly on the image

Upvotes: 3

iProgrammed
iProgrammed

Reputation: 980

- (void)awakeFromNib {
    timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(updatePhoto) userInfo:nil repeats:YES];
    count = 0;
}
// this creates a loop every 0.5 secs.
// then set up your image changes.

-(void)updatePhoto{
    count = count + 1;
    [self updateImage];
}

-(void)updateImage{
    if (count == 1){
        mainImage.image = [UIImage imageNamed:@\"img2.jpg\"];
    }
    if (count == 2){
        mainImage.image = [UIImage imageNamed:@\"img4.jpg\"];
    }
    if (count == 3){
        mainImage.image = [UIImage imageNamed:@\"img3.jpg\"];
    }
    if (count == 4){
        mainImage.image = [UIImage imageNamed:@\"img3.jpg\"];
    }
    else{
        mainImage.image = [UIImage imageNamed:@\"img1.jpg\"];
    }

}

Upvotes: 0

Related Questions