A easy way to pull to refresh, Thanks for MJRefresh
To run the example project, clone the repo, and run pod install
from the Example directory first.
- iOS >= 8.3
- Swift >= 3.0
-
TTARefresher is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "TTARefresher"
-
Manual import:
Drag All files in the MJRefresh folder to project, import the main file:
import TTARefresher
TTARefresherComponent
|
|- TTARefresherHeader
| |
| |- TTARefresherStateHeader
| |
| |- TTARefresherNormalHeader (DIRECTLY USE)
| |
| |- TTARefresherGifHeader (DIRECTLY USE)
|
|- TTARefresherFooter
|
|- TTARefresherAutoFooter
| |
| |- TTARefresherAutoStateFoote
| |
| |- TTARefresherAutoNormalFooter (DIRECTLY USE)
| |
| |- TTARefresherAutoGifFooter (DIRECTLY USE)
|
|- TTARefresherBackFooter
|
|- TTARefresherBackStateFoote
|
|- TTARefresherBackNormalFooter (DIRECTLY USE)
|
|- TTARefresherBackGifFooter (DIRECTLY USE)
/// For the Instance Methods
public var ttaRefresher: TTARefresher.TTARefresherProxy<Self>
// /For the Static Methods
public static var TTARefresher: TTARefresher.TTARefresherProxy<Self>.Type
/// Refresher Header
public var header: TTARefresher.TTARefresherHeader?
/// Refresher Footer
public var footer: TTARefresher.TTARefresherFooter?
/// Data Count in total
public var totalDataCount: Int
public enum TTARefresherState : Int {
/// Normal State
case idle
case pulling
case refreshing
case willRefresh
case noMoreData
}
/// Refresher State
open var state: TTARefresher.TTARefresherState
/// Whether the Refresher is Refreshing
public var isRefreshing: Bool
/// Current pulling Percentage
open var pullingPercent: CGFloat
/// Whether Auto Change the Refresher Alpha
public var isAutoChangeAlpha: Bool
/// The Refresher's superView, Readonly for subviews
public fileprivate(set) var scrollView: UIScrollView?
/// The ScrollView Original inset, Readonly for subviews
public internal(set) var scrollViewOriginalInset: UIEdgeInsets
/// Refresher Targer
public var refreshingTarget: AnyObject?
/// Refresher Action
public var refreshingAction: Selector?
/// Refresher Handler
public var refreshingHandler: TTARefresher.TTARefresherComponentRefreshingHandler?
/// Excuate While Begin Refreshing Completed
public var beginRefreshingCompletionHandler: TTARefresher.TTARefresherComponentBeginCompletionHandler?
/// Excuate While End Refreshing Completed
public var endRefreshingCompletionHandler: TTARefresher.TTARefresherComponentEndCompletionHandler?
/// Set Refreshing Target and Action
public func setRefreshingTarget(aTarget: AnyObject, anAction: Selector)
/// Begin Refreshing
public func beginRefreshing(_ completionHandler: TTARefresher.TTARefresherComponentBeginCompletionHandler? = default)
/// End Refreshing
public func endRefreshing(_ completionHandler: TTARefresher.TTARefresherComponentEndCompletionHandler? = default)
/// Refresher Header State Label
lazy public var stateLabel: UILabel
/// Refresher Header Time Label
public var lastUpdatedTimeLabel: UILabel
/// The margin between Label and left images
public var labelLeftInset: CGFloat
/// Set Custom Titles for State
public func set(title: String, for state: TTARefresher.TTARefresherState)
/// If true, the footer will be shown when there are data, otherwise, footer will be hidden
public var isAutoHidden: Bool
/// The ContentInset Bottom to ignore
public var ignoredScrollViewContentInsetBottom: CGFloat
/// Rest Refresher state `.noMoreData` to `.idle`
public func resetNoMoreData()
/// End Refresher and Set State With `.noMoreData`
public func endRefreshWithNoMoreData()
TTARefresherAutoFooter & TTARefresherBackFooter
/// Whether Footer Auto Refresh
public var isAutoRefresh: Bool
/// The percent when the footer appear will get refresh, default is 1.0
public var triggerAutoRefreshPercent: CGFloat
/// Whether Hide Footer
open var isHidden: Bool
TTARefresherAutoStateFoote & TTARefresherBackStateFooter
/// State Label
open var stateLabel: UILabel
/// Set Custom Titles for state
public func set(title: String, for state: TTARefresher.TTARefresherState)
/// Title for state
public func title(for state: TTARefresher.TTARefresherState) -> String?
TTARefresherAutoNormalFooter & TTARefresherBackNormalFooter & TTARefresherNormalHeader
/// Refresher Footer/ Header Indicator Style, default is `.gray`
public var indicatorStyle: UIActivityIndicatorViewStyle
/// Back Normal Footer's Arrow Image View
public var arrowImageView: UIImageView
TTARefresherAutoGifFooter & TTARefresherBackGifFooter & TTARefresherGifHeader
/// Gif Image View
open var gifImageView: UIImageView
/// Set Images And Animation Time for State
public func set(images: [UIImage]?, duration: TimeInterval?, for state: TTARefresher.TTARefresherState)
/// Set Images For State, Default Time is `images.count * 0.1`
public func set(images: [UIImage]?, for state: TTARefresher.TTARefresherState)
extension TTARefresherComponent {
open func prepare()
open func placeSubviews()
open func scrollViewContentSizeDidChange(_ change: [NSKeyValueChangeKey : Any]?)
open func scrollViewContentOffsetDidChange(_ change: [NSKeyValueChangeKey : Any]?)
open func scrollViewPanStateDidChange(_ change: [NSKeyValueChangeKey : Any]?)
}
let header = TTARefresherNormalHeader {
self.loadNew()
}
// or
let header = TTARefresherNormalHeader(refreshingTarget: self, refreshingAction: #selector(loadNew))
let header = TTARefresherGifHeader {
self.loadNew()
}
// or
let header = TTARefresherGifHeader(refreshingTarget: self, refreshingAction: #selector(loadNew))
// The margin between label and images
header.labelLeftInset = 10
let (idleImages, refreshingImages) = prepareAnimationImages()
header.set(images: idleImages, for: .idle)
header.set(images: refreshingImages, for: .refreshing)
header.lastUpdatedTimeLabel.isHidden = true
header.stateLabel.isHidden = true
header.lastUpdatedTimeLabel.isHidden = true
header.set(title: "Pull Me Down", for: .idle)
header.set(title: "Release Me To Refresh", for: .pulling)
header.set(title: "Come on, I'm getting the data", for: .refreshing)
let footer = TTARefresherAutoNormalFooter {
self.loadMore()
}
// or
let footer = TTARefresherAutoNormalFooter(refreshingTarget: self, refreshingAction: #selector(endLoadMore))
let footer = TTARefresherAutoGifFooter {
self.loadMore()
}
// or
let footer = TTARefresherAutoGifFooter(refreshingTarget: self, refreshingAction: #selector(loadMore))
let (idleImages, refreshingImages) = prepareAnimationImages()
footer.set(images: idleImages, for: .idle)
footer.set(images: refreshingImages, for: .refreshing)
let footer = TTARefresherBackNormalFooter {
self.loadMore()
}
// or
let footer = TTARefresherBackNormalFooter(refreshingTarget: self, refreshingAction: #selector(loadMore))
footer.stateLabel.isHidden = true
TobyoTenma, [email protected]
TTARefresher is available under the MIT license. See the LICENSE file for more info.