这个控件和LiteAutolayout一样也写了有一段时间了,使用swift实现,尽量做到简单易用,尽可能做到一行代码搞定。

先附上CocoRongPullToRefresh的源码地址:

https://github.com/MellongLau/CocoRongPullToRefresh

Thumbnail

下拉刷新功能应该是所用 app 中使用最频繁的功能了, 这个组件为你的 table view提供了最简单使用方式的下拉刷新特性。

用法

  • 下面代码是简单使用这个控件的例子
tableView.cr.enablePullRefresh {
	    // 调用远程服务器的接口.
        get("http://xxx.com/api/productlist") { dataList in
		// 更新 table view 的数据源
		self.tableView.datasource = dataList
		self.tableView.reloadData()
		// 完成刷新	
		self.tableView.cr.stopRefresh()
	}	
}

如你所看到的,我们只要上面几行代码就可以为你的 table view 添加下来刷新功能,如果你想要修改下拉刷新视图的背景颜色,可以参考下面代码:

tableView.cr.tintColor = UIColor.brown

最后,别忘了在view controller 的 deinit 方法中调用 remove() 方法移除当前页面对 CocoRongPullToRefresh 的引用。

deinit {
        tableView.cr.remove()
}

使用示例

下载 example 文件夹下的示例项目查看具体的用法。

安装

这里有两种方式添加 CocoRongPullToRefresh 到你的项目中。

CocoaPods

CocoaPods 推荐使用这种方式添加 CocoRongPullToRefresh 到你的项目中.

  1. 添加 CocoRongPullToRefresh 到 podfile.
pod "CocoRongPullToRefresh", "~> 1.0"
  1. 使用命令 pod install 安装所有的库.
  2. 引用 CocoRongPullToRefresh: import CocoRongPullToRefresh .

手动安装

使用 Terminal.app 运行以下命令:

$ git clone https://github.com/MellongLau/CocoRongPullToRefresh.git

或者直接下载并拷贝 CocoRongPullToRefresh 文件夹和添加引用到你的项目中.

要求

需要 Swift 3.0+ and iOS 8.0+ and ARC.

使用 CocoRongPullToRefresh?

如果你在你的项目中使用了 CocoRongPullToRefresh,请发邮件(邮件地址在下面)告诉我一声,我会把你的 app 的下载链接添加到这里!

贡献

欢迎为此项目提供任何的帮助,包括意见建议,资金,代码或者精神鼓励等,为此项目贡献代码请提交 pull request, 代码经过审核后会立即合并到主分支中

The End