Coder Social home page Coder Social logo

yangshebing / bgwaterfallsflowview Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 130 KB

一个Swift版基于UICollectionView封装的瀑布流控件,自带上下拉刷新功能。简单易用,集成到项目中仅仅只需要三步,轻轻松松分分钟。

Home Page: https://github.com/yangshebing/BGWaterfallsFlowView

License: MIT License

Ruby 3.07% Swift 96.93%
swift uicollectionview waterflow cocoapods

bgwaterfallsflowview's Introduction

BGWaterfallsFlowView

一个Swift版基于UICollectionView封装的瀑布流控件,自带上下拉刷新功能。简单易用,集成到项目中仅仅只需要三步,轻轻松松分分钟。

主要功能

  • 瀑布流布局
  • 上下拉刷新加载数据

环境要求

  • iOS 8.0+
  • Xcode 11.0+

Installation

CocoaPods:

 pod "BGWaterfallsFlowView"

手动安装:

导入"BGWaterfallsFlowView"文件夹至目标工程。

使用方法:

内部封装了BGWaterfallsFlowView和BGRefreshWaterfallsFlowView两个瀑布流视图。BGRefreshWaterfallsFlowView自带EGO下拉刷新和自定义加载更多,以下就是BGRefreshWaterfallsFlowView使用步骤(如使用BGWaterfallsFlowView详见使用方法)。

(1)初始化瀑布流控件视图

    let waterFlowView = BGRefreshWaterfallsFlowView(frame: view.bounds)
    //设置代理
    waterFlowView.dataSource = self
    waterFlowView.delegate = self
    //设置瀑布流列数
    waterFlowView.columnNum = 4
    //设置cell与cell之间的水平间距
    waterFlowView.horizontalItemSpacing = 10
    //设置cell与cell之间的垂直间距
    waterFlowView.verticalItemSpacing = 10
    waterFlowView.contentInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
    view.addSubview(waterFlowView)
    //注册Cells
    waterFlowView.register(BGCollectionViewCell.self, forCellWithReuseIdentifier: MainViewController.bgCollectionCellIdentify)

(2)实现BGWaterfallsFlowViewDataSource数据源代理方法

func waterFlowView(_ waterFlowView: BGWaterfallsFlowView, numberOfItemsIn section: NSInteger) -> Int {
    return dataList?.count ?? 0
}

func waterFlowView(_ waterFlowView: BGWaterfallsFlowView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    guard let cell = (waterFlowView.dequeueReusableCell(withReuseIdentifier: bgCollectionCellIdentify, for: indexPath)) as? BGCollectionViewCell else { return UICollectionViewCell() }
    ...
    return cell
}

//返回Cells指定的高度,一般从服务器获取。
func waterFlowView(_ waterFlowView: BGWaterfallsFlowView, heightForItemAt indexPath: IndexPath) -> CGFloat {
    //return cellHeight
    return 100 + (rand() % 100)
}

(3)实现BGRefreshWaterfallsFlowViewDelegate上下拉刷新加载数据代理方法

func pullDownWithRefreshWaterfallsFlowView(_ refreshWaterfallsFlowView: BGRefreshWaterfallsFlowView) {
    //下拉加载最新数据
    ...
    refreshWaterfallsFlowView.reloadData()
    refreshWaterfallsFlowView.pullDownDidFinishedLoadingRefresh()
}

func pullDownWithRefreshWaterfallsFlowView(_ refreshWaterfallsFlowView: BGRefreshWaterfallsFlowView) {
    //上拉加载更多数据
    ...
    refreshWaterfallsFlowView.reloadData()
    refreshWaterfallsFlowView.pullUpDidFinishedLoadingMore()
}

//点击cell的代理方法
func waterfallsFlowView(_ waterfallsFlowView: BGWaterfallsFlowView, didSelectItemAt indexPath: IndexPath) {
    print(indexPath)
}

Demo效果截图

demo.gif

协议许可

BGWaterfallsFlowView遵循MIT许可协议。有关详细信息,请参阅许可协议。

bgwaterfallsflowview's People

Contributors

yangshebing avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.