前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >swift - 带进度的无限轮播barnerswift - 带进度的无限轮播barner

swift - 带进度的无限轮播barnerswift - 带进度的无限轮播barner

作者头像
用户8893176
发布2021-08-09 11:27:26
1.1K0
发布2021-08-09 11:27:26
举报
文章被收录于专栏:小黑娃Henry

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

HRCycleView基于UICollectionView来实现。

功能包含:

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

cocopod

代码语言:javascript
复制
pod 'HRCycleView'

本地图片滚动视图

代码语言:javascript
复制
/// 本地图片
        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)

网络图片滚动视图

代码语言:javascript
复制
        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滚动视图

代码语言:javascript
复制
        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
    }

点击代理回调

代码语言:javascript
复制
func carouselView(carouselView: CarouselView, didSelectItemAt index: Int) {
        print("\(index)巴拉巴拉")
}

git-DEMO地址下载

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/10/16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • swift版本的带进度的无限轮播头部bar。
  • 功能包含:
  • cocopod
  • 本地图片滚动视图
  • 网络图片滚动视图
  • 自定义cell滚动视图
  • 点击代理回调
  • git-DEMO地址下载
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档