JCyclePictureView 1.0.4

JCyclePictureView 1.0.4

qq123123q 维护。



  • Zebra

Swift图片轮播 JCyclePictureView

使用UICollectionView编写的无限滚动轮播图,支持自定义cell和滚动方向。

License Platform

问题

如果您在使用过程中遇到任何问题,欢迎提交issue。

Swift4

支持Swift4及以上版本

CocoaPods

  • 支持CocoaPods
pod 'JCyclePictureView' 

支持

  • 支持仅图片
  • 支持文本图片组合
  • 支持横向滚动
  • 支持纵向滚动
  • 支持手势滑动
  • 支持点击回调
  • 支持图片数据的延迟加载
  • 支持无数据时,使用占位图占位
  • 支持本地图片显示和与网络图的混合显示
  • 支持设置系统UIPageControl的位置
  • 支持纯文本
  • 支持UIPageControl.currentPage图片样式修改

使用方法

// 数据源
let pictures: [String] = ["http://pic29.nipic.com/20130512/12428836_110546647149_2.jpg", "picture2", "picture3", "picture4", "picture5", "http://pic29.nipic.com/20130512/12428836_110546647149_2.jpg", "picture7"]

// 初始化
let cyclePictureView: JCyclePictureView = JCyclePictureView(frame: CGRect(x: 0, y: 20, width: self.view.frame.width, height: 150), pictures: pictures)

// 标题
cyclePictureView.titles = ["标题1", "标题2", "标题3", "标题4", "标题5", "标题6", "标题7"]
         
// 滚动方向
cyclePictureView.direction = .left
        
// 自动滚动时间
cyclePictureView.autoScrollDelay = 3
        
// pageControl 位置
cyclePictureView.pageControlStyle = .center
        
// 默认显示图
cyclePictureView.placeholderImage = #imageLiteral(resourceName: "picture1")
        
// 高亮圆点
cyclePictureView.pageControl.currentPageIndicatorTintColor
cyclePictureView.pageControl.currentPageIndicatorImage
        
// 默认圆点
cyclePictureView.pageControl.pageIndicatorTintColor
cyclePictureView.pageControl.pageIndicatorImage

// 点击回调
cyclePictureView.didTapAtIndexHandle = { index in
            
    print("点击了第 \(index + 1) 张图片")
}
        
self.view.addSubview(cyclePictureView)

// 自定义 cell
cyclePictureView.register([CustomCell.self], identifiers: ["CustomCell"]) { (collectionView, indexPath, picture) -> UICollectionViewCell in
            
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CustomCell", for: indexPath) as! CustomCell
            
    if picture.hasPrefix("http") {
                
        cell.imageView.kf.setImage(with: URL(string: picture), placeholder: nil)
                
    } else {
                
        cell.imageView.image = UIImage(named: picture)
    }
            
    cell.label.text = "自定义 cell"
            
    cell.label.textColor = UIColor.white
            
    return cell
}
        
// 自定义 nib cell
cyclePictureView.register(<#T##nibs: [UINib?]##[UINib?]#>, identifiers: <#T##[String]#>, customCellHandle: <#T##JCyclePictureViewCustomCellHandle##JCyclePictureViewCustomCellHandle##(UICollectionView, IndexPath) -> UICollectionViewCell#>)

示例

示例代码请参阅ViewController.swift

实现逻辑:http://www.jianshu.com/p/e13992f78aef

作者

Zebra,[email protected]