这是最简洁的刷新控件,当然这是在MJRefresh框架的基础之上修改的,用法很简单。
首先在Controller的extension 中写上定义方法。
public func configHeaderRefreshIndicatorView() -> MJRefreshNormalHeader {
let headerView = MJRefreshNormalHeader.init(refreshingTarget: self, refreshingAction: #selector(headerRefresh))
headerView?.stateLabel.textColor = UIColor.init(valueRGB: 0x5EDBFF)
headerView?.stateLabel.isHidden = true
for objView in (headerView?.subviews)! {
if objView.isKind(of: UIActivityIndicatorView.self) {
let indicatorView : UIActivityIndicatorView = objView as! UIActivityIndicatorView
indicatorView.color = UIColor.init(valueRGB: 0x5EDBFF)
}
}
return headerView!
}
@objc func headerRefresh() {
}
public func configFooterRefreshIndicatorView() -> MJRefreshBackNormalFooter {
let footerView = MJRefreshBackNormalFooter.init(refreshingTarget: self, refreshingAction: #selector(footerRefresh))
footerView?.stateLabel.textColor = UIColor.init(valueRGB: 0x5EDBFF)
footerView?.stateLabel.isHidden = false
for objView in (footerView?.subviews)! {
if objView.isKind(of: UIActivityIndicatorView.self) {
let indicatorView : UIActivityIndicatorView = objView as! UIActivityIndicatorView
indicatorView.color = UIColor.init(valueRGB: 0x5EDBFF)
}
}
return footerView!
}
@objc func footerRefresh() {
}
颜色值可以自定义,但先的 import MJRefresh
而在需要用到这个刷新数据的地方调用即可。
func configRefresh() {
tableView.mj_header = configHeaderRefreshIndicatorView()
tableView.mj_footer = configFooterRefreshIndicatorView()
}
override func headerRefresh() {
page = 1
dataRequest()
}
override func footerRefresh() {
page = 1 + page
dataRequest()
}
这样就很优雅的运用了刷新控件了。