在github上面有很多的第三方类库,大大节约了大家的开发时间

下载地址:https://github.com/gsdios/SDCycleScrollView

现已支持cocoapods导入:pod 'SDCycleScrollView','~> 1.61'

效果

具体实现代码

#import "ViewController.h"
#import "SDCycleScrollView.h" @interface ViewController () <SDCycleScrollViewDelegate> @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; self.view.backgroundColor = [UIColor colorWithRed:0.98 green:0.98 blue:0.98 alpha:0.99];
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"005.jpg"]];
backgroundView.frame = self.view.bounds;
[self.view addSubview:backgroundView]; UIScrollView *demoContainerView = [[UIScrollView alloc] initWithFrame:self.view.frame];
demoContainerView.contentSize = CGSizeMake(self.view.frame.size.width, );
[self.view addSubview:demoContainerView]; self.title = @"轮播Demo"; // 情景一:采用本地图片实现
NSArray *imageNames = @[@"h1.jpg",
@"h2.jpg",
@"h3.jpg",
@"h4.jpg",
@"h7" // 本地图片请填写全名
]; // 情景二:采用网络图片实现
NSArray *imagesURLStrings = @[
@"https://ss2.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=a4b3d7085dee3d6d2293d48b252b5910/0e2442a7d933c89524cd5cd4d51373f0830200ea.jpg",
@"https://ss0.baidu.com/-Po3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=a41eb338dd33c895a62bcb3bb72e47c2/5fdf8db1cb134954a2192ccb524e9258d1094a1e.jpg",
@"http://c.hiphotos.baidu.com/image/w%3D400/sign=c2318ff84334970a4773112fa5c8d1c0/b7fd5266d0160924c1fae5ccd60735fae7cd340d.jpg"
]; // 情景三:图片配文字
NSArray *titles = @[@"新建交流QQ群:185534916 ",
@"感谢您的支持,如果下载的",
@"如果代码在使用过程中出现问题",
@"您可以发邮件到gsdios@126.com"
]; CGFloat w = self.view.bounds.size.width; // >>>>>>>>>>>>>>>>>>>>>>>>> demo轮播图1 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> // 本地加载 --- 创建不带标题的图片轮播器
SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(, , w, ) shouldInfiniteLoop:YES imageNamesGroup:imageNames];
cycleScrollView.delegate = self;
cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
[demoContainerView addSubview:cycleScrollView];
// --- 轮播时间间隔,默认1.0秒,可自定义
//cycleScrollView.autoScrollTimeInterval = 4.0; // >>>>>>>>>>>>>>>>>>>>>>>>> demo轮播图2 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> // 网络加载 --- 创建带标题的图片轮播器
SDCycleScrollView *cycleScrollView2 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(, , w, ) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]]; cycleScrollView2.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
cycleScrollView2.titlesGroup = titles;
cycleScrollView2.currentPageDotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
[demoContainerView addSubview:cycleScrollView2]; // --- 模拟加载延迟
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
cycleScrollView2.imageURLStringsGroup = imagesURLStrings;
}); /*
block监听点击方式 cycleScrollView2.clickItemOperationBlock = ^(NSInteger index) {
NSLog(@">>>>> %ld", (long)index);
}; */ // >>>>>>>>>>>>>>>>>>>>>>>>> demo轮播图3 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> // 网络加载 --- 创建自定义图片的pageControlDot的图片轮播器
SDCycleScrollView *cycleScrollView3 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(, , w, ) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
cycleScrollView3.currentPageDotImage = [UIImage imageNamed:@"pageControlCurrentDot"];
cycleScrollView3.pageDotImage = [UIImage imageNamed:@"pageControlDot"];
cycleScrollView3.imageURLStringsGroup = imagesURLStrings; [demoContainerView addSubview:cycleScrollView3]; } #pragma mark - SDCycleScrollViewDelegate - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
NSLog(@"---点击了第%ld张图片", (long)index); [self.navigationController pushViewController:[NSClassFromString(@"DemoVCWithXib") new] animated:YES];
} /* // 滚动到第几张图回调
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index
{
NSLog(@">>>>>> 滚动到第%ld张图", (long)index);
} */ @end

iOS开发之 用第三方类库实现轮播图的更多相关文章

  1. iOS最笨的办法实现无限轮播图(网络加载)

    iOS最笨的办法实现无限轮播图(网络加载) 简单的做了一下: 使用方法: 把 请求返回的 图片地址(字符串类型)放进数组中就行 可以使用SDWebImage(我就是用的这个)等..需要自己导入并引用, ...

  2. iOS开发之 用第三方类库实现ScrollView

    转自:http://www.cnblogs.com/qianLL/p/5369127.html   在github上面有很多的第三方类库,大大节约了大家的开发时间 下载地址:https://githu ...

  3. vue移动音乐app开发学习(三):轮播图组件的开发

    本系列文章是为了记录学习中的知识点,便于后期自己观看.如果有需要的同学请登录慕课网,找到Vue 2.0 高级实战-开发移动端音乐WebApp进行观看,传送门. 完成后的页面状态以及项目结构如下: 一: ...

  4. iOS开发常用的第三方类库

    在iOS开发中不可避免的会用到一些第三方类库,它们提供了很多实用的功能,使我们的开发变得更有效率:同时,也可以从它们的源代码中学习到很多有用的东西. Reachability 检测网络连接 用来检查网 ...

  5. 【转】iOS开发常用的第三方类库

    原文: http://blog.csdn.net/xiazailushang/article/details/9716043 在iOS开发中不可避免的会用到一些第三方类库,它们提供了很多实用的功能,使 ...

  6. iOS开发项目实战——Swift实现图片轮播与浏览

    近期開始开发一个新的iOS应用,自己决定使用Swift.进行了几天之后,发现了一个非常严峻的问题.那就是无论是书籍,还是网络资源,关于Swift的实在是太少了,随便一搜全都是OC实现某某某功能.就算是 ...

  7. iOS开发那些事儿(一)轮播器

    前言 市面上绝大部分的APP被打开之后映入眼帘的都是一个美轮美奂的轮播器,所以能做出一个符合需求.高效的轮播器成为了一个程序员的必备技能.所以今天的这篇博客就来谈谈轮播器这个看似简单的控件其中蕴含的道 ...

  8. iOS开发之常用第三方框架(下载地址,使用方法,总结)

    iOS开发之常用第三方框架(下载地址,使用方法,总结) 说句实话,自学了这么久iOS,如果说我不知道的但是又基本上都摸遍了iOS相关知识,但是每次做项目的时候,遇到难一点的地方或者没试过的东西就闷了. ...

  9. ReactNative新手学习之路04 组件化开发轮播图swiper支持安卓和IOS

    react native 新手之路04 组件化开发轮播图swiper支持安卓和IOS npm install react-native-carousel --save git 地址Properties ...

随机推荐

  1. 使用.NET 4.0+ 操作64位系统中的注册表

    一.64位系统中的注册表 以 LocalMachine 中的启动项为例: 64位应用的注册表位置还是在: SOFTWARE\Microsoft\Windows\CurrentVersion\Run 而 ...

  2. JS虚拟键盘

    由于是触摸屏,所以需要一款JS虚拟键盘.上网找了一个好用的VirtualKeyboard,作了修改. 修改该插件参考的博客文章:http://www.cnblogs.com/xinggong/arch ...

  3. Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive.

    调试网站时,异常出现:Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive. S ...

  4. Razor练习1

    学习ASP.NET MVC, Razor语法必须掌握,这篇学习: Razor code blocks are enclosed in @{ ... }Inline expressions (varia ...

  5. c# TCP Socket通讯基础

    在做网络通讯方面的程序时,必不可少的是Socket通讯. 那么我们需要有一套既定的,简易的通讯流程. 如下: <pre name="code" class="csh ...

  6. CSS使图片变灰

    为了悼念,各大网站都纷纷将自己的站点颜色调灰,就连图片也一样,到底如何实现的呢,请看下面的代码. 〈img src="http://hovertree.com/hvtimg/201512/f ...

  7. datatable删除行

    先列出正确的写法,如果你只想马上改错就先复制吧, protected void deleteDataRow(int RowID,DataTable dt) { ; i >= ; i--) { i ...

  8. No.013:Roman to Integer

    问题: Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from ...

  9. python2.x 默认编码问题

    python2.x中处理中文,是一件头疼的事情.网上写这方面的文章,测次不齐,而且都会有点错误,所以在这里打算自己总结一篇文章. 我也会在以后学习中,不断的修改此篇博客. 这里假设读者已有与编码相关的 ...

  10. python 学习笔记9(面向对象)

    面向过程.函数式.面向对象 面向过程:根据业务逻辑从上到下写垒代码 函数式:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 面向对象(Object Oriented Programmin ...