• This repository has been archived on 01/Jul/2020
  • Stars
    star
    552
  • Rank 78,109 (Top 2 %)
  • Language
    Swift
  • License
    MIT License
  • Created almost 8 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

【Deprecated】Pull to refresh in Swift, easy to use, easy to customize(下拉刷新/QQ/淘宝/优酷/雅虎天气/大众点评)

PullToRefreshKit

Version Platform Language Swift Package Manager License

The example project contains some hot App refresh example.

Taobao YouKu QQ Video
Yahoo Weather Dian Ping QQ

Require

  • iOS 8
  • Swift 4+
  • XCode 10.2+

For Swift 3, See branch Swift3

Support

UITableView/UICollectionView/UIScrollView/UIWebView

  • Pull to refresh.
  • Pull/Tap to load more.
  • Pull left/right to load more(Currently only support chinese)
  • Elastic refresh
  • Easy to customize
  • English and Chinese

Install

CocoaPod

pod "PullToRefreshKit"

Carthage

github "LeoMobileDeveloper/PullToRefreshKit"

Swift Package Manager

.package(url: "https://github.com/LeoMobileDeveloper/PullToRefreshKit.git",  from: "0.8.9")

Useage

What is a container? A container is the object that hold the scrollView reference, most time it is a UIViewController object

Pull down to refresh

self.tableView.configRefreshHeader(container:self) { [weak self] in
    delay(2, closure: {
        self?.tableView.switchRefreshHeader(to: .normal(.success, 0.5))
    })
}

If you do not want any delay:

self.tableView.switchRefreshHeader(to: .normal(.none, 0.0))

Pull up to load more

Support three mode to fire refresh action

  • Tap
  • Scroll
  • Scroll and Tap
self.tableView.configRefreshFooter(container:self) { [weak self] in
	delay(1.5, closure: {
	    self?.tableView.switchRefreshFooter(to: .normal)
	})
};

Remove footer:

self.tableView.switchRefreshFooter(to: .removed)

No more Data

self.tableView.switchRefreshFooter(to: .noMoreData)

Pull left to exit

scrollView.configSideRefresh(with: DefaultRefreshLeft.left(), container:self, at: .left) {
   self.navigationController?.popViewController(animated: true)
};

Pull right to Pop

let right  = DefaultRefreshRight.right()
right.setText("👈滑动关闭", mode: .scrollToAction)
right.setText("松开关闭", mode: .releaseToAction)
right.textLabel.textColor = UIColor.orange
scrollView.configSideRefresh(with: right, container:self, at: .right) { [weak self] in
    self?.navigationController?.popViewController(animated: true)
};

Config the default refresh text

PullToRefershKit offer SetUp operator,for example

let header = DefaultRefreshHeader.header()
header.setText("Pull to refresh", mode: .pullToRefresh)
header.setText("Release to refresh", mode: .releaseToRefresh)
header.setText("Success", mode: .refreshSuccess)
header.setText("Refreshing...", mode: .refreshing)
header.setText("Failed", mode: .refreshFailure)
header.tintColor = UIColor.orange
header.imageRenderingWithTintColor = true
header.durationWhenHide = 0.4
self.tableView.configRefreshHeader(with: header,container:self) { [weak self] in
    delay(1.5, closure: {
        self?.models = (self?.models.map({_ in random100()}))!
        self?.tableView.reloadData()
        self?.tableView.switchRefreshHeader(to: .normal(.success, 0.3))
    })
};

Customize

You just need to write a UIView sub class,and make it conforms to these protocols

  • RefreshableHeader
  • RefreshableFooter
  • RefreshableLeftRight

For exmaple,to create a custom header

    //Height of the refresh header
    func heightForHeader()->CGFloat
    
    //Distance from top when in refreshing state
    func heightForRefreshingState()->CGFloat
   
    //Will enter refreshing state,change view state to refreshing in this function
    func didBeginrefreshingState()

    //The refreshing task is end.Refresh header will hide.Tell user the refreshing result here.
    func didBeginHideAnimation(result:RefreshResult)
    
    //Refresh header is hidden,reset all to inital state here
    func didCompleteHideAnimation(result:RefreshResult)
    
    //Distance to drag to fire refresh action ,default is heightForRefreshingState
    optional func heightForFireRefreshing()->CGFloat
    
    //Percent change during scrolling
    optional func percentUpdateDuringScrolling(percent:CGFloat)
    
    //Duration of header hide animation
    optional func durationOfHideAnimation()->Double
    

Author

Leo, [email protected]

License

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

More Repositories

1

ios-developer-tools

Tools that every iOS developer should know.
Swift
1,618
star
2

Blogs

一点心得 - iOS,Swift,React Native,Python...
Objective-C
1,577
star
3

ReactNativeMaterials

React Native的中文参考资料,包括开源库,文字/视频资料,相关工具等
697
star
4

awesome-rxswift

An "awesome" type curated list of RxSwift library and learning material
Swift
498
star
5

QTEventBus

iOS事件总线,支持AppDelegate解耦,支持基于响应链的局部总线
Objective-C
423
star
6

MDTable

A data-driven UITableView framework
Swift
162
star
7

ImageMaskTransition

Elegant image transition between view controllers,support both Modal and Push
Swift
120
star
8

LeoDanmakuKit

An iOS Danmaku Kit (添加纯文字弹幕)
Objective-C
52
star
9

LHPerformanceStatusBar

A status bar to show FPS, CPU and memory usage
Objective-C
51
star
10

WCGradientCircleLayer

Draw Gradient Layer from one color to another
Objective-C
36
star
11

ParallexBanner

【Deprecated】A banner scrollview to show images with parallex effect
Swift
30
star
12

LHNavigationController

像网易新闻那样,支持全屏push/pop的导航控制器(A NavigationController that allow you to push/pop with full screen gesture)
Objective-C
26
star
13

DraggableTableView

【Deprecated】Extension for the UITableView that allows a user to move cells with long press and drop.
Swift
26
star
14

LHProgressHUD

A modern ProgressHUD with wonderful animation
Objective-C
23
star
15

LHCityPickerController

包含所有地级市的城市选择控制器,和大众点评类似
Objective-C
13
star
16

React-Native-Files

A project used to store temp files
12
star
17

SwiftDynamicTableviewHeight

A project about how to do dynamic height with system cell
Swift
12
star
18

LeoMobileDeveloper

1
star