igrrik
igrrik

Reputation: 467

How to create image slider in iOS?

I'm wondering how to create image slider like those that we are using to look through pictures in different iOS apps, for example in Photos or Airbnb app.

Is it a page controller with image views in it? Or is it a uicollectionview? Or is it just a scrollview?

I've searched for this a lot, and though I found a good library on github, I haven't found any common solution, that everybody uses.

This is an example of image slider in airbnb app. Image slider under navigation bar

Upvotes: 2

Views: 10983

Answers (3)

Graycodder
Graycodder

Reputation: 467

You can use UPCarouselFlowLayout It is very simple with to create an image slide like in airBnB with the library.

Upvotes: 1

Dharmesh Dhorajiya
Dharmesh Dhorajiya

Reputation: 3984

Try this code to create Image Slider Show Using UIScrollView.

int x=0;
self.scrollView.pagingEnabled=YES;
NSArray *image=[[NSArray alloc]initWithObjects:@"1.png",@"2.png",@"3.png", nil];
for (int i=0; i<image.count; i++) 
{
    UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(x, 0,[[UIScreen mainScreen] bounds].size.width, self.scrollView.frame.size.height)];
    img.image=[UIImage imageNamed:[image objectAtIndex:i]];
    x=x+[[UIScreen mainScreen] bounds].size.width;
    [self.scrollView addSubview:img];
}
self.scrollView.contentSize=CGSizeMake(x, self.scrollView.frame.size.height);
self.scrollView.contentOffset=CGPointMake(0, 0);

Upvotes: 5

Parama Dharmika
Parama Dharmika

Reputation: 108

There are one great image slider lib i used on my project https://github.com/kimar/KIImagePager, definitely worth checking. Here are few steps to integrate the library with your project.

  1. Download and import the library to your project
  2. Add view to your nib file (if you are using it with nib file), set the view class to use KIImagePager
  3. Set the properties as seen on their example page.

And there you go, you will have working image slider on your project.

Upvotes: 2

Related Questions