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

查看:15
本文介绍了如何在 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?还是只是一个滚动视图?

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 应用程序中图像滑块的示例.

This is an example of image slider in airbnb app.

推荐答案

试试这个代码来使用 UIScrollView 创建 Image Slider Show.

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天全站免登陆