如何在iOS中创建图像滑块? [英] How to create image slider in iOS?

查看:83
本文介绍了如何在iOS中创建图像滑块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何创建图像滑块,就像我们用来浏览不同iOS应用中的图片一样,例如在照片或Airbnb应用中。

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.

它是一个带有图像视图的页面控制器吗?
或者它是一个uicollectionview?
或者它只是一个scrollview?

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

我已经搜索了很多,虽然我在github上找到了一个很好的库,但我还没找到每个人都使用的任何常见解决方案。

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.

这是airbnb app中图像滑块的一个示例。

This is an example of image slider in airbnb app.

推荐答案

尝试使用此代码创建图像滑块显示使用 UIScrollView

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);

这篇关于如何在iOS中创建图像滑块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆