介绍: 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,默认为UIViewContentModeScaleToFill2. 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(0, 0, 0, 0));}];[self.view addSubview:self.bgScrollView];[self.bgScrollView mas_makeConstraints:^(MASConstraintMaker *make) {make.edges.mas_equalTo(self.view).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));}];
}- (void)local_storage
{[self.bgScrollView addSubview:self.localCycleScrollView];[self.localCycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {make.left.mas_equalTo(self.bgScrollView).with.offset(0);make.width.mas_equalTo(kWidth);make.top.mas_equalTo(self.bgScrollView).with.offset(20);make.height.mas_equalTo(180);}];
}- (void)webImage
{[self.bgScrollView addSubview:self.webCycleScrollView];[self.webCycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {make.left.mas_equalTo(self.bgScrollView).with.offset(0);make.width.mas_equalTo(kWidth);make.top.mas_equalTo(self.localCycleScrollView.mas_bottom).with.offset(20);make.height.mas_equalTo(180);}];
}- (void)cuatomPageControl
{[self.bgScrollView addSubview:self.customCycleScrollView];[self.customCycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {make.left.mas_equalTo(self.bgScrollView).with.offset(0);make.width.mas_equalTo(kWidth);make.top.mas_equalTo(self.webCycleScrollView.mas_bottom).with.offset(20);make.height.mas_equalTo(180);}];
}- (void)onlyText
{[self.bgScrollView addSubview:self.textCycleScrollView];[self.textCycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {make.left.mas_equalTo(self.bgScrollView).with.offset(0);make.width.mas_equalTo(kWidth);make.top.mas_equalTo(self.customCycleScrollView.mas_bottom).with.offset(20);make.height.mas_equalTo(40);}];
}#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, 1200);}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 = 1;}return _localCycleScrollView;
}- (SDCycleScrollView *)webCycleScrollView
{if (!_webCycleScrollView){self.webCycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];// 分页控件的位置self.webCycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;// 标题self.webCycleScrollView.titlesGroup = @[@"1",@"2",@"3"];// 网络图片数组NSArray * imagesURLStrings = @[@"1",@"2",@"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图片轮播 (基础篇——UIScrollView实现方式)

    简述 : 人生不发返程的车票,一旦出发了,决不能返回. 人生只有一次,无悔的人生才是成功的人生,不要期待与奢望 "下一次" 如何. 过去的人生中,我们的路程中可能充满了欢笑与忧伤, ...

  2. IOS开发基础之图片轮播器-12

    IOS开发基础之图片轮播器-12 核心代码 // // ViewController.m // 12-图片轮播器 // // Created by 鲁军 on 2021/2/2. //#import ...

  3. 图片轮播c语言,IOS开发之UIScrollView实现图片轮播器的无限滚动

    IOS开发之UIScrollView实现图片轮播器的无限滚动 简介 在现在的一些App中常常见到图片轮播器,一般用于展示广告.新闻等数据,在iOS内并没有现成的控件直接实现这种功能,但是通过UIScr ...

  4. ios ScrollerView之图片轮播器

    ios ScrollerView之图片轮播器 今天项目中用到了图片轮播器,写完之后贴到博客里来记录一下,也方便有兴趣的同学学习 #import "JYHCarouselController. ...

  5. unity实现图片轮播效果_unity 背景无限循环滚动效果

    背景无限循环滚动效果如下示: 步骤如下: 导入背景图片后,设置图片的格式,如下图: 2.图片格式也可以设置是Texture格式,但是Wrap Mode 一定要是Repeat[重复发生]:然后记得App ...

  6. 网站项目必备——12款白富美型 jQuery 图片轮播插件

    转自:http://www.cnblogs.com/lhb25/archive/2013/01/06/jquery-image-carousel-effect.html 图片轮播是网站中的常用功能,用 ...

  7. DEDECMS后台上传banner图控制图片轮播

    将图片轮播做到后台控制,无论是dedecms还是其他的程序都是一样的重要,方便客户自己调试,不然动不动就拿FTP开刷,一个是操作不方便,增加了使用上的难度,另外也有一定的风险,很可能由于操作生疏,误操 ...

  8. android首页图片轮播效果,Android_Android自动播放Banner图片轮播效果,先看一下效果图支持本地图 - phpStudy...

    Android自动播放Banner图片轮播效果 先看一下效果图 支持本地图片以及网络图片or本地网络混合. 使用方式: android:id="@+id/banner" andro ...

  9. 淘宝装修:第一日 —— 图片轮播

    先添加一个自定义内容区,进入源码编辑,如下图所示: 添加源码如下: <TABLE border=0 cellSpacing=0 cellPadding=0 width=773 height=22 ...

最新文章

  1. IE下的优秀js调试工具Companion.JS
  2. 【ABAP】OO ALV 概述
  3. Python3 字符串复制
  4. php is_post,PHP发送get、post请求的6种方法简明总结
  5. 认识代码编辑区域与解决方案区域 005
  6. 第4章 变量、作用域和内存问题
  7. EasyCriteria 2.0 – JPA标准应该很容易
  8. 2.Node.js access_token的获取、存储及更新
  9. 一键批量检测微信是否被好友删除,支持最新版微信
  10. 粒子群算法几个适应度评价函数
  11. Few-Shot Object Detection with Attention-RPN and Multi-Relation Detector 论文翻译
  12. 19. 正则表达式(二)
  13. python实现明星专家系统:人脸识别自动比对
  14. Error:(3, 50) java: 程序包com.n.c.caa.cds.commons.constants不存在
  15. Django 项目编码问题1UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd2 in position 0: invalid contin
  16. s:iterator各种遍历用法
  17. Nginx介绍及原理简单分析
  18. Re-id多粒度网络(MGN)的PPT汇报总结
  19. 采集CSDN博客中的RSS订阅小功能
  20. vue3项目名称报错

热门文章

  1. 360浏览器异常关闭,错过点击恢复,如何重新恢复原有网页?
  2. 【BZOJ3470】Freda’s Walk
  3. DNSPod十问Neha Naik:以人民币结算海外IT业务的可能性?
  4. diamond专题(三)—— diamond架构
  5. Matplotlib坐标轴范围
  6. 培训html源码,前端培训——html源码笔记
  7. 大数据之路——数据挖掘
  8. mysql别名引号与引用问题
  9. RVDS-RealView Development Suite 4 0 Professional软件
  10. 基于支持向量机的谐波分析研究与实现