How to create image slider in iOS?(如何在 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 中创建图像滑块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 iOS 中创建图像滑块?
基础教程推荐
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
