swift - 带进度的无限轮播barner

swift版本的带进度的无限轮播头部bar。

HRCycleView基于UICollectionView来实现。

功能包含:

  • 支持单张图片
  • 支持带进度条样式
  • 支持持续时间自定义
  • 支持本地图片显示,网路图显示,本地图片和网路图混合显示
  • 支持自定义图片展示Cell(纯代码和Xib创建都支持)
  • 支持UIPageControl具体位置设置
  • 支持UIPageControl显示颜色设置
  • 支持图片点击回调

cocopod

pod 'HRCycleView'

本地图片滚动视图

/// 本地图片
        let carouselView = CarouselView(CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: vMain.frame.height),
                                        ["img1.jpg","img2.jpg","img3.jpg","img4.jpg"],
                                        placeholderImage: UIImage.creatImageWithColor(color: .black),
                                        pageLocation: .CenterBottom(bottom: 12),
                                        autoScrollDelay: 3)
        carouselView.pageIndicatorTintColor = .blue
        carouselView.delegate = self
        vMain.addSubview(carouselView)

网络图片滚动视图

        let carouselView2 = CarouselView(CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: vMain.frame.height),
                                         picUrl,
                                         placeholderImage: UIImage(named: "img1.jpg")!,
                                         pageLocation: .LeftBottom(leading: 15, bottom: 15),
                                         autoScrollDelay: 5)
        carouselView2.pageIndicatorTintColor = .orange
        carouselView2.delegate = self
        vMain2.addSubview(carouselView2)

自定义cell滚动视图

        let carouselView3 = CarouselView(CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: vMain.frame.height),
                                         picUrl,
                                         placeholderImage: UIImage(named: "img1.jpg")!,
                                         pageLocation: .RightBottom(trailing: 15, bottom: 15),
                                         autoScrollDelay: 3)
        carouselView3.pageIndicatorTintColor = .green
        carouselView3.delegate = self
        carouselView3.register([UINib.init(nibName: "CustomCollectionViewCell", bundle: nil)], identifiers: ["CustomCollectionViewCell"])
        vMain3.addSubview(carouselView3)

// 自定义Cell-Delegate-(纯代码和Xib创建都支持)

    func carouselView(carouselView: CarouselView, collectionView: UICollectionView, cellForItemAt indexPath: IndexPath, picture: String) -> UICollectionViewCell? {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CustomCollectionViewCell", for: indexPath) as! CustomCollectionViewCell
        cell.lable.text = "自定义Cell\n第 \(indexPath.item) 项"
        cell.image.kf.setImage(with: URL(string: picture))
        return cell
    }

点击代理回调

func carouselView(carouselView: CarouselView, didSelectItemAt index: Int) {
        print("\(index)巴拉巴拉")
}

git-DEMO地址下载

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。