YSRefreshControl
下拉刷新、上拉加载控件
环境
swift5.0、iOS11.0
使用步骤
1、导入框架
pod 'YSRefreshControl'
2、导入命名空间
import YSRefreshControl
重要API
1、创建
下拉
YSRefreshControl_helper.ys_createPullDownView(normalText: nil, pullingText: nil, refreshingText: nil, controlSize: nil, bgColor: nil, target: self, action: #selector(pullDownAction))
上拉
YSRefreshControl_helper.ys_createPullUpView(loadText: nil, hasNoMoreText: nil, errorText: nil, bgColor: nil, controlSize: nil, target: self, action: #selector(pullUpAction))
当然,也可以使用各自的便利构造函数创建,这里只是提供一个帮助类来创建而已
2、属性
下拉
/// 刷新次数,每次结束刷新的时候会+1
var ys_refreshTimes:Int
/// 是否是首次刷新,refreshTimes <= 0
var ys_firstRefresh:Bool
/// 是否正在刷新
var ys_isRefreshing:Bool
上拉
/// 是否正在加载中
var ys_isLoading:Bool
3、方法
下拉
// 设置文本样式
func ys_setupLabelStyle(font: UIFont, textColor: UIColor)
// 设置文本显示
public func ys_setupLabelText(normalText: String, pullingText: String, refreshingText: String)
// 结束刷新
func ys_endRefreshing()
// 自动刷新
func ys_autoRefresh()
上拉
// 设置文本样式
func ys_setupLabelStyle(font: UIFont, textColor: UIColor)
// 设置文本显示
public func ys_setupLabelText(loadingText: String, noMoreText: String, errorText: String)
// 重新设置箭头图片,建议1x下为40 * 40
func ys_setupArrowImage(image: UIImage)
// 开始加载,需手动调用,不用再判断canPullUp的值,内部封闭好了
public func ys_beginLoading()
// 结束加载-正常情况,一定要传canPullUp
public func ys_endLoading(canPullUp: Bool)
// 结束加载-异常情况,如:网络错误,点击会进行重试(发送一次valueChanged事件)
public func ys_endLoading_error()
示例代码
ViewController里面的即为示例代码,使用过程非常简单,不再做详情介绍。