Giter Club home page Giter Club logo

pulltorefreshkit's Introduction

[![Version](https://img.shields.io/cocoapods/v/YLPullToRefreshKit.svg?style=flat )](http://cocoapods.org/pods/YLPullToRefreshKit) [![Platform](http://img.shields.io/badge/platform-ios-blue.svg?style=flat )](https://developer.apple.com/iphone/index.action) [![Language](http://img.shields.io/badge/language-swift-brightgreen.svg?style=flat )](https://developer.apple.com/swift) [![Swift Package Manager](https://img.shields.io/badge/SPM-compatible-orange.svg)](https://swift.org/package-manager) [![License](http://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat )](http://mit-license.org)

Requirements

  • iOS 13.0+
  • Swift 5.1+

Features

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

To integrate YLPullToRefreshKit into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '13.0'
use_frameworks!

target 'MyApp' do
  # your other pod
  # ...
  pod 'YLPullToRefreshKit'
end

Run pod install to build your dependencies.

Swift Package Manager

Select File > Swift Packages > Add Package Dependency. Enter https://github.com/YuLeiFuYun/YLPullToRefreshKit.git in the "Choose Package Repository" dialog.

Useage

What is a container? A container is the object that hold the scrollView reference, most time it is a UIViewController object

Pull down to refresh

self.tableView.configRefreshHeader(container:self) { [weak self] in
    // success
    self?.tableView.switchRefreshHeader(to: .normal(.success, 0.5))
    // failure
    self?.tableView.switchRefreshHeader(to: .normal(.failure, 0.5))
    
    // if no more data
    self?.tableView.switchRefreshFooter(to: .removed)
}

Pull up to load more

Support three mode to fire refresh action

  • Tap
  • Scroll
  • Scroll and Tap
self.tableView.configRefreshFooter(container:self) { [weak self] in
	// has more data
    self?.tableView.switchRefreshFooter(to: .normal)
    // no more data
    self?.tableView.switchRefreshFooter(to: .removed)
};

Pull left to exit

scrollView.configSideRefresh(with: DefaultRefreshLeft.left(), container:self, at: .left) {
    self.navigationController?.popViewController(animated: true)
};

Pull right to Pop

let right  = DefaultRefreshRight.right()
right.setText("👈滑动关闭", mode: .scrollToAction)
right.setText("松开关闭", mode: .releaseToAction)
right.textLabel.textColor = UIColor.orange
scrollView.configSideRefresh(with: right, container:self, at: .right) { [weak self] in
    self?.navigationController?.popViewController(animated: true)
};

Config the default refresh text

YLPullToRefreshKit offer SetUp operator,for example

let header = DefaultRefreshHeader.header()
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.tintColor = UIColor.orange
header.imageRenderingWithTintColor = true
header.durationWhenHide = 0.4
self.tableView.configRefreshHeader(with: header,container:self) { [weak self] in
    delay(1.5, closure: {
        self?.models = (self?.models.map({_ in random100()}))!
        self?.tableView.reloadData()
        self?.tableView.switchRefreshHeader(to: .normal(.success, 0.3))
    })
};

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

    //Height of the refresh header
    func heightForHeader()->CGFloat
    
    //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 didBeginHideAnimation(result:RefreshResult)
    
    //Refresh header is hidden,reset all to inital state here
    func didCompleteHideAnimation(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 durationOfHideAnimation()->Double
    

License

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

pulltorefreshkit's People

Contributors

leomobiledeveloper avatar pinguo-tanglei avatar stevapple avatar yuleifuyun avatar z415073783 avatar

Watchers

 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.