Latest 1.0.1
Homepage https://github.com/lihei12345/MTORefresher
License MIT
Platforms ios 8.0, requires ARC
Authors

MTORefresher is a Swift implementation of pull-to-refresh, include pull-down and pull-up. Use 1 line of code can make this. Also you can use Component protocol to custom your own pull-to-refresh Component.

Install

Now Support Swift 3:

pod 'MTORefresher', '~> 1.0.0'
# Optional
pod 'MTORefresher/BasicComponent', '~> 1.0.0'

For Swift 2.x:

pod 'MTORefresher', '~> 0.1.1'
# Optional
pod 'MTORefresher/BasicComponent', '~> 0.1.1' 

Basic

Setup

// pull down
let topView: SimpleTopComponent = SimpleTopComponent()
// pull up
let bottomView: SimpleBottomComponent = SimpleBottomComponent()
refresher = tableView
    .mto_refresher()
    .add(topView: topView) { [weak self] in
        self?.reload()
    }
    .add(bottomView: bottomView, enableTap: true) { [weak self] in
        self?.loadMore()
    }
// hide has bottom view
refresher?.canPullUp = false

Trigger

// trigger pull down
refresher?.triggerLoad(type: .PullDown)
// trigger pull up
refresher?.triggerLoad(type: .PullUp)

Load Data

private func reload() {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(0.1*Double(NSEC_PER_SEC))), dispatch_get_main_queue()) {
        self.count = 2
        self.tableView.reloadData()
        // stop loading
        self.refresher?.stopLoad()
        // show bottom view
        self.refresher?.canPullUp = true
        self.refresher?.hasMore = true
    }
}

private func loadMore() {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(0.3*Double(NSEC_PER_SEC))), dispatch_get_main_queue()) {
        self.count += 20
        self.tableView.reloadData()
        // stop loading
        self.refresher?.stopLoad()
        let hasMore = (rand()%2) == 0 ? true : false
        // has more data
        self.refresher?.hasMore = hasMore
    }
}

Custom Component

Just create subview that confirms to Componet protocol. See SimpleTopComponent and SimpleBottomComponent for more! It’s very easy to extend.

Latest podspec

{
    "name": "MTORefresher",
    "version": "1.0.1",
    "summary": "MTORefresher is a Swift implementation of pull-to-refresh",
    "description": "MTORefresher is a Swift implementation of pull-to-refresh, include pull-down and pull-up. Use 1 line of code can make this. Also you can use Component protocol to custom your own pull-to-refresh Component.",
    "homepage": "https://github.com/lihei12345/MTORefresher",
    "license": "MIT",
    "authors": {
        "lifuqiang": "[email protected]"
    },
    "source": {
        "git": "https://github.com/lihei12345/MTORefresher.git",
        "tag": "1.0.1"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "default_subspecs": "Core",
    "pushed_with_swift_version": "3.0",
    "subspecs": [
        {
            "name": "Core",
            "source_files": "Source/*.swift",
            "frameworks": "UIKit"
        },
        {
            "name": "BasicComponent",
            "source_files": "BasicComponent/*.swift",
            "dependencies": {
                "MTORefresher/Core": []
            },
            "resources": "BasicComponent/*.{png,jpg}"
        }
    ]
}

Pin It on Pinterest

Share This