wantedly/SwiftRefresher

Name: SwiftRefresher

Owner: Wantedly, Inc.

Description: SwiftRefresher is one of the alternatives of UIRefreshControl.

Forked from: morizotter/SwiftRefresher

Created: 2016-11-09 01:57:24.0

Updated: 2017-03-03 08:49:23.0

Pushed: 2017-07-10 17:31:14.0

Homepage:

Size: 2884

Language: Swift

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

SwiftRefresher

Version License Platform Carthage compatible

SwiftRefresher solves your problem on UIRefreshControl on UITableView in UIViewController! SwiftRefresher is one of the alternatives of UIRefreshControl. Moreover, it is very customizable!

refresher.gif

Features
Usage
Basic

Add codes below and add it to UITableView with srf_addRefresher. The closure will be called when refresh starts.

refresher = RefresherView { [weak self] () -> Void in
self?.updateItems()

eView.srf_addRefresher(refresher)

And call srf_endRefreshing() whenever/wherever your refreshing task finished.

bleView.srf_endRefreshing()
Use with a little Customize

The view of SwiftRefresher is independent from its main system. The only requirement is to conform to SwfitRefresherEventReceivable protocol. Default view is SimpleRefreshView. You can use it with a little customization like this below:

refresher = Refresher { [weak self] () -> Void in
self?.updateItems()

esher.createCustomRefreshView { () -> SwfitRefresherEventReceivable in
return SimpleRefreshView(activityIndicatorViewStyle: .White)

eView.srf_addRefresher(refresher)

In this example, I changed SimpleRefreshView's activityIndicatorViewStyle to .White. But you can customize more with create your own refreh view!

Customize!!!

Just create a view with conforming to SwfitRefresherEventReceivable. SwfitRefresherEventReceivable has one required function func didReceiveEvent(event: SwiftRefresherEvent). Through this function, refresher send the view the events. The events are below:

ic enum SwiftRefresherEvent {
case Pull(offset: CGPoint, threshold: CGFloat)
case StartRefreshing
case EndRefreshing
case RecoveredToInitialState

For example, preset SimpleRefreshView has this easy codes.

ic func didReceiveEvent(event: SwiftRefresherEvent) {
switch event {
case .Pull:
    pullingImageView.hidden = false
case .StartRefreshing:
    pullingImageView.hidden = true
    activityIndicatorView.startAnimating()
case .EndRefreshing:
    activityIndicatorView.stopAnimating()
case .RecoveredToInitialState:
    break
}

RecoveredToInitialState means that after EndRefreshing, the view will go back to initial state. And then the state becamed to the initial, this event will be called.

Runtime Requirements
Installation and Setup
Installing with Carthage

Just add to your Cartfile:

ub "morizotter/SwiftRefresher"
Installing with CocoaPods

CocoaPods is a centralised dependency manager that automates the process of adding libraries to your Cocoa application. You can install it with the following command:

m update
m install cocoapods
ds --version

To integrate SwiftRefresher into your Xcode project using CocoaPods, specify it in your Podfile and run pod install.

form :ios, '8.1'
frameworks!
"SwiftRefresher", '~>0.9.0'
Manual Installation

To install SwiftRefresher without a dependency manager, please add all of the files in /SwiftRefresher to your Xcode Project.

Contribution

Please file issues or submit pull requests for anything you?d like to see! We're waiting! :)

License

SwiftRefresher is released under the MIT license. Go read the LICENSE file for more information.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.