/GSRefresh

Fully customizable drop-down refresh and load more.

Primary LanguageSwiftMIT LicenseMIT

GSRefresh

Example

Refresh

Set the drop-down refresh:

scrollView.refresh.setup(view: CustomRefreshView) {
	/// do something...
	self.scrollView.refresh.endRefreshing()
}

Immediately trigger the refresh state:

scrollView.refresh.beginRefreshing()

End the refresh state:

scrollView.refresh.endRefreshing()

Custom Refresh View

extension SomeView: CustomRefresh {

    /// @optional, default is 44.
    /// Sets the height displayed when refreshing.
    var refreshingKeepHeight: CGFloat { return 44 }
    
    /// @optional, default is .init(top: 30, left: 0, bottom: 0, right: 0).
    /// -top: increase the trigger refresh distance.
    /// -left and right: set the horizontal offset.
    /// -bottom: increase the distance from scrollview.
    var refreshInsets: UIEdgeInsets { return .zero }

    /**
     In this method, set the UI in different states.
     There are three status types: initial, pulling, refreshing.
    
     - parameter previous: previous refresh state
     - parameter newState: new refresh state
    */
    func refreshStateChanged(previous: RefreshState, newState: RefreshState) {
  	    /// do something...
    }
  
}

let someView = SomeView(frame: ...)

scrollView.refresh.setup(view: someView) {
	/// do something...
	self.scrollView.refresh.endRefreshing()
}

LoadMore

Set the pull-up load:

scrollView.loadMore.setup(view: CustomLoadMoreView) {
	/// do something...
	self.scrollView.loadMore.endRefreshing(noMore: Bool)
}

Immediately trigger the refresh state:

scrollView.loadMore.beginRefreshing()

End the refresh state and set whether no longer try to load new data:

scrollView.loadMore.endRefreshing(noMore: Bool)

Reset to continue loading data:

scrollView.loadMore.reset()

No longer try to load new data:

scrollView.loadMore.noMore()

Custom LoadMore View

extension SomeView: CustomLoadMore {

    /// @optional, default is 0.
    /// Set the preload configuration, such as half screen 0.5, one screen is 1, two screens are 2, no preload is 0.
    var preload: CGFloat { get }
    
    /// @optional, default is true.
    /// When there is no more data, is it necessary to keep the height of the custom view? If it is false, it will not be displayed.
    var isVisibleNoMore: Bool { get }

    /// @optional, default is true.
    /// Whether to send a request only once per drag. If it is false, it will be called continuously when the offset changes.
    var isOnlyRefreshPerDrag: Bool { get }
    
    /// @optional, default is .zero.
    /// -top: increase the distance from scrollview.
    /// -left and right: set the horizontal offset.
    /// -bottom: increase the distance from the bottom.
    var loadMoreInsets: UIEdgeInsets { get }
    
    /**
     In this method, set the UI in different states.
     There are three status types: initial, refreshing, noMore.
     
     - parameter previous: previous load more state
     - parameter newState: new load more state
     */
    func loadMoreStateChanged(previous: LoadMoreState, newState: LoadMoreState)
  	    /// do something...
    }
  
}

let someView = SomeView(frame: ...)

scrollView.loadMore.setup(view: someView) {
	/// do something...
	self.scrollView.loadMore.endRefreshing(noMore: Bool)
}

Requirements

Master

  • iOS 8.0+
  • Xcode 10+ (Swift 4.2 + Swift 5.0)
  • iOS 8.0+
  • Xcode 9.x (Swift 4)
  • iOS 8.0+
  • Xcode 9.x (Swift 3.x)

Installation

In your Podfile:

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

pod "GSRefresh"

And in your *.swift:

import GSRefresh

In your Cartfile:

github "wxxsw/GSRefresh"

And in your *.swift:

import GSRefresh

License

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