介绍: SDCycleScrollView 是一款非常强大的轮播图第三方. 轮播流畅,手滑流畅.使用方便.自定义简单. 可以更改pageControl.

一. Demo地址 https://pan.baidu.com/disk/home#list/path=%2F总结%2FDemo-图片轮播

二.效果截图.

三.代码.

#import "ViewController.h"

#import "Masonry.h"

#import "SDCycleScrollView.h"

#define kWidth [UIScreen mainScreen].bounds.size.width

@interface ViewController () <SDCycleScrollViewDelegate>

@property (nonatomic, strong) UIImageView  * bgImageView;
@property (nonatomic, strong) UIScrollView * bgScrollView; // 本地图片
@property (nonatomic, strong) SDCycleScrollView * localCycleScrollView; // 网络图片
@property (nonatomic, strong) SDCycleScrollView * webCycleScrollView; // 自定义pageControl
@property (nonatomic, strong) SDCycleScrollView * customCycleScrollView; // 跑马灯效果
@property (nonatomic, strong) SDCycleScrollView * textCycleScrollView; @end /** 滚动控制接口
1. autoScrollTimeInterval 自动滚动间隔,默认为2s.
2. infiniteLoop 是否无限循环.
3. autoScroll 是否滚动设置.
4. scrollDirection 图片滚动方向.
5. delegate 设置代理.
6. adjustWhenControllerViewWillAppera 解决viewWillAppear时出现时轮播图卡在一半的问题,在控制器viewWillAppear时调用此方法
7.
*/ /** 自定义样式接口
1. bannerImageViewContentMode 轮播图的ContentMode,默认为UIViewContentModeScaleToFill
2. placeholderImage 占位图 用于网络
3. showPageControl 是否显示分页控件
4. hidesForSinglePage 是否在只有一张图片时隐藏pageControl,默认为Yes.
5. onlyDisplayText 只显示文字轮播
6. pageControlStyle 样式. 默认为动画样式
7. pageControlAliment 分页控件的位置
8. pageControlBottomOffset 分页控件距离轮播图的右边间距.
9. pageControlDotSize 分页控件小圆标的大小
10. currentPageDotColor当前分页控件小圆标颜色
11. currentPageDotImage 当前分页控件小圆标的图片
12. pageDotImage 其他分页控件小圆标图片
13. titleLabelTextColor 轮播文字label字体颜色
14. titleLabelTextFont 轮播文字label的字体大小
15. titleLabelBackgroundColor 轮播文字label背景颜色
16. titleLabelHeight 轮播文字字体高度
*/ /** 清除缓存
1. clearImagesCache
[SDCycleScrollView clearImagesCache];
*/ @implementation ViewController #pragma mark - 生命周期
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated]; // 如果你发现你的CycleScrollview会在viewWillAppear时图片卡在中间位置,你可以调用此方法调整图片位置
// [你的CycleScrollview adjustWhenControllerViewWillAppera];
} - (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
} #pragma mark viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad]; [self basicSetting]; [self addBgModule]; // 本地存储的图片
[self local_storage]; // 网络图片
[self webImage]; [self cuatomPageControl]; [self onlyText];
} #pragma mark - 系统代理
#pragma mark SDCycleScrollViewDelegate // 点击图片代理方法
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
NSLog(@"---点击了第%ld张图片", (long)index); // 清理缓存
[SDCycleScrollView clearImagesCache]; } // 滚动到第几张图片的回调
-(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index
{
NSLog(@">>>>>> 滚动到第%ld张图", (long)index);
} #pragma mark - 点击事件 #pragma mark - 实现方法
#pragma mark 基本设置
- (void)basicSetting
{
self.title = @"";
} - (void)addBgModule
{
[self.view addSubview:self.bgImageView];
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(self.view).with.insets(UIEdgeInsetsMake(, , , ));
}]; [self.view addSubview:self.bgScrollView];
[self.bgScrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(self.view).with.insets(UIEdgeInsetsMake(, , , ));
}];
} - (void)local_storage
{ [self.bgScrollView addSubview:self.localCycleScrollView];
[self.localCycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.bgScrollView).with.offset();
make.width.mas_equalTo(kWidth);
make.top.mas_equalTo(self.bgScrollView).with.offset();
make.height.mas_equalTo();
}];
} - (void)webImage
{
[self.bgScrollView addSubview:self.webCycleScrollView];
[self.webCycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.bgScrollView).with.offset();
make.width.mas_equalTo(kWidth);
make.top.mas_equalTo(self.localCycleScrollView.mas_bottom).with.offset();
make.height.mas_equalTo();
}];
} - (void)cuatomPageControl
{
[self.bgScrollView addSubview:self.customCycleScrollView];
[self.customCycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.bgScrollView).with.offset();
make.width.mas_equalTo(kWidth);
make.top.mas_equalTo(self.webCycleScrollView.mas_bottom).with.offset();
make.height.mas_equalTo();
}];
} - (void)onlyText
{
[self.bgScrollView addSubview:self.textCycleScrollView];
[self.textCycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.bgScrollView).with.offset();
make.width.mas_equalTo(kWidth);
make.top.mas_equalTo(self.customCycleScrollView.mas_bottom).with.offset();
make.height.mas_equalTo();
}];
} #pragma mark - setter & getter - (UIImageView *)bgImageView
{
if (!_bgImageView)
{
self.bgImageView = [[UIImageView alloc] init];
self.bgImageView.image = [UIImage imageNamed:@"005.jpg"];
}
return _bgImageView;
} - (UIScrollView *)bgScrollView
{
if (!_bgScrollView)
{
self.bgScrollView = [[UIScrollView alloc] init];
self.bgScrollView.backgroundColor = [UIColor clearColor]; self.bgScrollView.contentSize = CGSizeMake(kWidth, );
}
return _bgScrollView;
} #pragma mark 轮播
- (SDCycleScrollView *)localCycleScrollView
{
if (!_localCycleScrollView)
{
NSArray * localImageArray = @[@"h1.jpg",
@"h2.jpg",
@"h3.jpg",
@"h4.jpg",
@"h7" // 本地图片请填写全名
]; self.localCycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero shouldInfiniteLoop:YES imageNamesGroup:localImageArray];
self.localCycleScrollView.delegate = self;
self.localCycleScrollView.scrollDirection = UICollectionViewScrollDirectionHorizontal;
self.localCycleScrollView.autoScrollTimeInterval = ;
}
return _localCycleScrollView;
} - (SDCycleScrollView *)webCycleScrollView
{
if (!_webCycleScrollView)
{
self.webCycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]]; // 分页控件的位置
self.webCycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight; // 标题
self.webCycleScrollView.titlesGroup = @[@"",@"",@""]; // 网络图片数组
NSArray * imagesURLStrings = @[@"",@"",@"http://pic1.win4000.com/wallpaper/4/510f446941311.jpg"];
self.webCycleScrollView.imageURLStringsGroup = imagesURLStrings; }
return _webCycleScrollView;
} - (SDCycleScrollView *)customCycleScrollView
{
if (!_customCycleScrollView)
{
self.customCycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]]; self.customCycleScrollView.currentPageDotImage = [UIImage imageNamed:@"pageControlCurrentDot"];
self.customCycleScrollView.pageDotImage = [UIImage imageNamed:@"pageControlDot"]; // 网络图片数组
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"
];
self.customCycleScrollView.imageURLStringsGroup = imagesURLStrings;
}
return _customCycleScrollView;
} - (SDCycleScrollView *)textCycleScrollView
{
if (!_textCycleScrollView)
{
self.textCycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:nil]; self.textCycleScrollView.scrollDirection = UICollectionViewScrollDirectionVertical;
self.textCycleScrollView.onlyDisplayText = YES; self.textCycleScrollView.titlesGroup = @[@"第一个",@"第二个",@"第三个"];
}
return _textCycleScrollView;
} @end

设置默认展示第几个

1. SDCycleScrollView.h文件里面添加一个初始化属性

 @property(nonatomic,assign)NSUInteger firstIndex;//滚动的起始页

 2. SDCycleScrollView.m里面的layoutSubviews方法添加

if(self.firstIndex !=0){

[_mainView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.firstIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:NO];

}

iOS-图片轮播-SDCycleSCrollView的使用的更多相关文章

  1. iOS 图片轮播图(自动滚动)

    iOS 图片轮播图(自动滚动) #import "DDViewController.h" #define DDImageCount 5 @interface DDViewContr ...

  2. IOS 图片轮播实现原理 (三图)

    IOS 图片轮播实现原理的一种 图片轮播所要实现的是在一个显示区域内通过滑动来展示不同的图片. 当图片较少时我们可以采用在滚动视图上添加很多张图片来实现. 但是如果图片数量较多时,一次性加载过多图片会 ...

  3. ios图片轮播效果

    代码地址如下:http://www.demodashi.com/demo/11959.html ImageCarousel 简单封装的图片轮播器 内存过大由于我加载的图片分辨率较高(4k) 文件目录 ...

  4. iOS图片轮播

    基于ScrollView的图片播放 ScrollView的方法 NSTime的循环 UIPageControl的运用 委托方法 基于iphone5 未做屏幕的适配 import "ViewC ...

  5. iOS 简易无限滚动的图片轮播器-SDCycleScrollView

    @interface ViewController () <</span>SDCycleScrollViewDelegate> @end @implementation Vie ...

  6. iOS开发UI篇—UIScrollView控件实现图片轮播

    iOS开发UI篇—UIScrollView控件实现图片轮播 一.实现效果 实现图片的自动轮播            二.实现代码 storyboard中布局 代码: #import "YYV ...

  7. IOS第六天(3:scrollView 图片轮播器)

    IOS第六天(3:scrollView 图片轮播器) #import "HMViewController.h" #define kImageCount 5 @interface H ...

  8. 【转】 iOS开发UI篇—UIScrollView控件实现图片轮播

    原文:http://www.cnblogs.com/wendingding/p/3763527.html iOS开发UI篇—UIScrollView控件实现图片轮播 一.实现效果 实现图片的自动轮播 ...

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

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

  10. ios之无限 自动 图片轮播器的实现

    比较之前发布的手动无限图片轮播器进行了改进.实现了自动无限轮播的功能.比较适合团购标题分类下面的轮播器功能. 实现思路: * 开启一个定时器,把操作放入消息循环池.每隔一定时间,操作执行一次. * 注 ...

随机推荐

  1. UIScrollView offset in UINavigationController

    转:UIScrollView offset in UINavigationController 通过设置viewCtronller的 self.automaticallyAdjustsScrollVi ...

  2. MySQL存储引擎选型

    一.MySQL的存储引擎 完整的引擎说明还是看官方文档:http://dev.mysql.com/doc/refman/5.6/en/storage-engines.html 这里介绍一些主要的引擎 ...

  3. HTTP 错误 500.21 - Internal Server Error 处理程序“ExtensionlessUrlHandler-Integrated-4.0”在其模块列表中有一个错误模块“ManagedPipelineHandler”

    导致这个错误出现的原因是因为.net Framework4.0没有注册 解决方法:打开运行命令行,运行下面的命令: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30 ...

  4. 对于程序开发者看书(指实在的书而不是PDF)的好处。(个人看法而已)

    书是实在的东西.不同PDF.他能带你进入一种学习态度的环境 书上已经所列了知识点.看了.那些知识点就是你的. 第一次看,未必完全理解到里面的东西.说不定过几天,几周,几个月,甚至几年.再看.就有可能看 ...

  5. ECshop导入淘宝数据包乱码问题解决方法

    ECshop在导入淘宝数据包的时候出现数据乱码. 测试版本 ecshop2.73 利用淘宝助手导出一个数据包(.csv),不要一次全部商品导出,最好是将数据包控制在1M左右,因为ecshop对上传文件 ...

  6. 采用ODAC,ODBC连接Oracle【转】

    采用ODAC,ODBC连接Oracle 在没有装oracle的环境中,偶尔会需要访问数据库(Word文档查看数据,开发项目运行等等),简单介绍我用过的方案. 一:ODAC 1.介绍.ODAC,全称:o ...

  7. C#集合 -- Equality和Order插件

    在前面的文章C#相等性比较和C#排序比较中,我已经叙述了类型相等,类型哈希,和类型比较的.NET标准协议.实现了这些协议的类型在一个字典或者列表中也可以正常工作.但是需要注意的是: 只有当类型的Equ ...

  8. SQL Server 连接问题圣经-命名管道

    SQL Server 连接问题圣经-命名管道 (1) APGC DSD Team 12 Jan 2011 1:24 AM 3 一.前言 在使用SQL Server 的过程中,用户遇到的最多的莫过于连接 ...

  9. Ubuntu14.04安装中文输入法以及解决Gedit中文乱码问题

    1 设置中文显示环境 1. 打开System Settings 2. 打开Personal-> Language Support. 会弹出如下对话框,提示你“语言支持没安装完整”. 点击“Rem ...

  10. 使用 Portable Class Library(可移植类库)开发 Universal Windows App

    今天在这里跟大家聊聊关于 Windows Universal 应用夸平台的问题,首先Universal Windows App的定义相信大家已经有所了解了(如果你是一个刚刚接触 Universal A ...