Latest 0.1.0
Homepage https://github.com/TMTBO/TTARefresher
License MIT
Platforms ios 8.0
Authors

A easy way to pull to refresh, Thanks for MJRefresh

CI Status
Version
License
Platform

Contents

Example

Requirements

Installation

File Structures

Api

[How to use ](#How_to_use )

Author

License

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS >= 8.3
  • Swift >= 3.0

Installation

  • 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

File Structures

    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)

Api

Name Space

/// 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

Refresher States

    public enum TTARefresherState : Int {
        /// Normal State
        case idle

        case pulling

        case refreshing

        case willRefresh

        case noMoreData
    }

TTARefresherComponent

    /// 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)

TTARefresherStateHeader

    /// 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)

TTARefresherFooter

    /// 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]?)
}

How to use

Header


Default Header

    let header = TTARefresherNormalHeader {
        self.loadNew()
    }
   // or
   let header = TTARefresherNormalHeader(refreshingTarget: self, refreshingAction: #selector(loadNew))

Default Header

Gif Header

    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)

Gif Header

Header Hide Time

    header.lastUpdatedTimeLabel.isHidden = true

Header Hide Time

Header Hide Time And State

    header.stateLabel.isHidden = true
    header.lastUpdatedTimeLabel.isHidden = true

Header Hide Time And State

Header Custom Text

    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)

Header Hide Time And State

Footer


Footer Default Auto

    let footer = TTARefresherAutoNormalFooter {
        self.loadMore()
    }
   // or
   let footer  = TTARefresherAutoNormalFooter(refreshingTarget: self, refreshingAction: #selector(endLoadMore))

Footer Default Auto

Auto Gif Footer

    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)

Auto Gif Footer

Back Footer

    let footer = TTARefresherBackNormalFooter {
        self.loadMore()
    }
    // or
    let footer = TTARefresherBackNormalFooter(refreshingTarget: self, refreshingAction: #selector(loadMore))

Back Footer

Auto Gif Hide State

    footer.stateLabel.isHidden = true

Auto Gif Hide State


Author

TobyoTenma, [email protected]

License

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

Latest podspec

{
    "name": "TTARefresher",
    "version": "0.1.0",
    "summary": "TTARefresher is Swift version of `MJRefresh`",
    "description": "TTARefresher is Swift version of `MJRefresh`, TTARefresher can work with UIScrollView, UITableView, UICollectionView and UIWebView, WKWebView. Othewise, THANKS the author of `MJRefresh`",
    "homepage": "https://github.com/TMTBO/TTARefresher",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "TMTBO": "[email protected]"
    },
    "source": {
        "git": "https://github.com/TMTBO/TTARefresher.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "TTARefresher/Classes/**/*",
    "resource_bundles": {
        "TTARefresher": [
            "TTARefresher/Resources/*.png",
            "TTARefresher/Resources/*.lproj"
        ]
    },
    "pushed_with_swift_version": "3.1"
}

Pin It on Pinterest

Share This