ZZCarouselSwift
Gif 来先解释
更新内容
- 添加数据源等于1的情况判断。隐藏pagecontrol,禁用自动滚动
- 添加主动刷新的reloaddata 方法
- 添加主动开始/停止轮播器的方法
- 添加关闭自动滚动方法
- 变更定时器启动位置
轮播器优势:
- 基于UICollectionView,实现无限轮播
- 可以通过自定义UICollectionViewCell来定制轮播器。
- 支持纯图片轮播,纯文字轮播,以及各种自定义Cell形式轮播。
- 支持使用Kingfisher加载图片
- 支持cocoapods
- 点击轮播器delegate方法执行
- 示例中添加了仿淘宝样式的效果
方法说明
注册UICollectionviewCell,PS:必须实现的方法,不实现会崩溃
func registerCarouselCell(cellClass: AnyClass)
设置自动滚动间隔时间
func setAutoScrollTimeInterval(timeInterval: Float)
数据源为AnyObject类型。PS:必须实现的方法。轮播中的所有数据都通过此方法传递
func setCarouselData(carouselData: [AnyObject])
UIPageControl默认颜色
func setDefaultPageColor(color: UIColor)
UIPageControl当前颜色
func setCurrentPageColor(color: UIColor)
设置UIPageControl对齐方式,枚举类型:左、中、右
func setPageControlAlignment(alignment: ZZCarouselPageAlignment)
设置是否隐藏PageControl。PS:通常在文字轮播中设置此方法
func setHiddenPageControl(hidden: Bool)
是否关闭滚动手势,PS:一般在文字轮播的情况下调用此方法
func setDisableScroll(disableScroll: Bool)
是否关闭自动滚动
func setIsAutoScroll(isAutoScroll: Bool)
枚举说明
ZZCarouselPageAlignment UIPageControl对齐方式设置
case left // 居左
case right // 居右
case center // 居中
ZZCarouselScrollDirection Carousel滚动方向设置
case left // 从左到右
case right // 从右到左
case top // 从上到下
case bottom // 从下到上
使用方法
/// <#Description#>
///
/// - Parameters:
/// - frame: <#frame description#>
/// - direction: 指定滚动滚动方向
let carousel = ZZCarouselView.init(frame: CGRect(x: 0, y: 64, width: self.view.frame.size.width, height:self.view.frame.size.height / 3), direction: ZZCarouselScrollDirection.left)
// 注册自定义的Cell,PS:非常有必要,一定要实现的方法
carousel.registerCarouselCell(cellClass: Example1Cell.classForCoder())
carousel.setCurrentPageColor(color: UIColor.red)
carousel.setDefaultPageColor(color: UIColor.yellow)
carousel.delegate = self
// 设置自动滚动的间隔时间
carousel.setAutoScrollTimeInterval(timeInterval: 2)
carousel.setPageControlAlignment(alignment: ZZCarouselPageAlignment.right)
carousel.tag = 1001;
self.view.addSubview(carousel)
// 非常有必要,给实例的CarouselView传递数据,数组<任意Object>
carousel.setCarouselData(carouselData: data as [AnyObject])
安装方法
- 手动安装:将ZZCarouselSwift文件夹拖拽到工程内即可
- 自动安装:pod 'ZZCarouselSwift', '~> 1.0.6'
PS
如有问题,可以提供各种代码贡献。逐步完善,还需要各位iOSer的支持。