/PullToRefreshKit

Pull to refresh in Swift, easy to use, easy to customize

Primary LanguageSwiftMIT LicenseMIT

PullToRefreshKit

Apps Using Downloads Version Platform Language License Build Status

The example project contains some hot App refresh example.

Taobao YouKu QQ Video QQ
Curve Yahoo Weather Dian Ping

Require

  • iOS 8
  • Swift 3.0

For Swift 2.3, See branch Swift2

Support

UITableView/UICollectionView/UIScrollView/UIWebView

  • Pull to refresh.
  • Pull/Tap to load more.
  • Pull left/right to load more(Currently only support chinese)
  • Elastic refresh
  • Easy to customize
  • English and Chinese

Install

CocoaPod

pod "PullToRefreshKit"

Carthage

github "LeoMobileDeveloper/PullToRefreshKit"

Useage

Pull down to refresh

 self.tableView.setUpHeaderRefresh { [weak self] in
    delay(1.5, closure: { 
         self?.tableView.endHeaderRefreshing(.Success)
    })
 }

Add a delay if you want user to see the result of refresh result

self?.tableView.endHeaderRefreshing(.Success,delay: 0.5)

Pull up to load more

Support three mode to fire refresh action

  • Tap
  • Scroll
  • Scroll and Tap
 self.tableView.setUpFooterRefresh {  [weak self] in
     delay(1.5, closure: {
         self?.tableView.endFooterRefreshing()
     })
 }

Pull left to exit

 scrollView.setUpLeftRefresh { [weak self] in
     self?.navigationController?.popViewControllerAnimated(true)
 }

Pull right to enter

 scrollView.setUpRightRefresh { [weak self] in
     let nvc = DefaultBannerController()
     self?.navigationController?.pushViewController(nvc, animated: true)
 }

Config the default refresh text

PullToRefershKit offer SetUp operator,for example

self.tableView.setUpHeaderRefresh { [weak self] in
    delay(1.5, closure: {
        self?.tableView.endHeaderRefreshing(.Success)
    })
}.SetUp { (header) in
    header.setText("Pull to refresh", mode: .pullToRefresh)
    header.setText("Release to refresh", mode: .releaseToRefresh)
    header.setText("Success", mode: .refreshSuccess)
    header.setText("Refreshing...", mode: .refreshing)
    header.setText("Failed", mode: .refreshFailure)
    header.setText("Error", mode: .refreshError)
    header.textLabel.textColor = UIColor.orangeColor()
    header.imageView.image = nil
}

Customize

You just need to write a UIView sub class,and make it conforms to these protocols

  • RefreshableHeader
  • RefreshableFooter
  • RefreshableLeftRight

For exmaple,to create a custom header

    //Distance from top when in refreshing state
    func heightForRefreshingState()->CGFloat
   
    //Will enter refreshing state,change view state to refreshing in this function
    func didBeginrefreshingState()

    //The refreshing task is end.Refresh header will hide.Tell user the refreshing result here.
    func didBeginEndRefershingAnimation(result:RefreshResult)
    
    //Refresh header is hidden,reset all to inital state  here
    func didCompleteEndRefershingAnimation(result:RefreshResult)
    
    //Distance to drag to fire refresh action ,default is heightForRefreshingState
    optional func heightForFireRefreshing()->CGFloat
    
    //Percent change during scrolling
    optional func percentUpdateDuringScrolling(percent:CGFloat)
    
    //Duration of header hide animation
    optional func durationWhenEndRefreshing()->Double
    

Author

Leo, leomobiledeveloper@gmail.com

License

PullToRefreshKit is available under the MIT license. See the LICENSE file for more info.