Easily add vertical and horizontal pull to refresh to any UIScrollView. Can also add multiple pull-to-refesh views at once.

Overview

This is a fork from the famous SVPullToRefresh pod with 2 additional functionalities:

  • Can add multiple pull-to-refresh views into one single UIScrollView
  • Support both vertical and horizontal pull to refresh

Vertical Horizontal

Installation

Add pod 'HTPullToRefresh' to your Podfile (remove the SVPullToRefresh pod if you had added it before)

Usage

(see sample Xcode project in /Demo)

Adding Pull to Refresh

If you don't specify the position, it will add to top by default

[tableView addPullToRefreshWithActionHandler:^{
  //do stuff
}];

or if you want it from the bottom

[tableView addPullToRefreshWithActionHandler:^{
  //do stuff
} position:SVPullToRefreshPositionBottom];

or from the left

[tableView addPullToRefreshWithActionHandler:^{
  //do stuff
} position:SVPullToRefreshPositionLeft];

or right?

[tableView addPullToRefreshWithActionHandler:^{
  //do stuff
} position:SVPullToRefreshPositionRight];

or add multiple pull-to-refresh views all at once

// add top
[tableView addPullToRefreshWithActionHandler:^{
  //do stuff
} position:SVPullToRefreshPositionBottom];

// then add bottom
[tableView addPullToRefreshWithActionHandler:^{
  //do stuff
} position:SVPullToRefreshPositionLeft];

Retrieve Pull to Refresh View

Retrieve first pull-to-refresh view:

tableView.pullToRefreshView

Retrieve pull-torefresh view at a specific position:

[tableView pullToRefreshViewAtPosition:SVPullToRefreshPositionBottom];

Since we have multiple pull-to-refresh views inside a UIScrollView, we can retrieve all of them by:

tableView.pullToRefreshViews

Customization

The pull to refresh view can be customized using the following properties/methods:

@property (nonatomic, strong) UIColor *arrowColor;
@property (nonatomic, strong) UIColor *textColor;
@property (nonatomic, readwrite) UIActivityIndicatorViewStyle activityIndicatorViewStyle;

- (void)setTitle:(NSString *)title forState:(SVPullToRefreshState)state;
- (void)setSubtitle:(NSString *)subtitle forState:(SVPullToRefreshState)state;
- (void)setCustomView:(UIView *)view forState:(SVPullToRefreshState)state;

For instance, you would set the arrowColor property using:

tableView.pullToRefreshView.arrowColor = [UIColor whiteColor];

Adding Infinite Scrolling

[tableView addInfiniteScrollingWithActionHandler:^{
    // append data to data source, insert new cells at the end of table view
    // call [tableView.infiniteScrollingView stopAnimating] when done
}];

If you’d like to programmatically trigger the loading (for instance in viewDidAppear:), you can do so with:

[tableView triggerInfiniteScrolling];

You can temporarily hide the infinite scrolling view by setting the showsInfiniteScrolling property:

tableView.showsInfiniteScrolling = NO;

Customization

The infinite scrolling view can be customized using the following methods:

- (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle;
- (void)setCustomView:(UIView *)view forState:(SVInfiniteScrollingState)state;

You can access these properties through your scroll view's infiniteScrollingView property.

Under the hood

SVPullToRefresh extends UIScrollView by adding new public methods as well as a dynamic properties.

It uses key-value observing to track the scrollView's contentOffset.

Credits

SVPullToRefresh is brought to you by Sam Vermette and contributors to the project. If you have feature suggestions or bug reports, feel free to help out by sending pull requests or by creating new issues. If you're using SVPullToRefresh in your project, attribution would be nice.

Big thanks to @seb_morel for his Demistifying the Objective-C runtime talk which really helped for this project.

Hat tip to Loren Brichter for inventing pull-to-refresh.

You might also like...
Customizable pull-to-refresh control,written in pure Swift.
Customizable pull-to-refresh control,written in pure Swift.

What is it This project is heavily inspired by CBStoreHouseRefreshControl which is Objective-C implemented. SurfingRefreshControl provides you a chanc

One gesture, many actions. An evolution of Pull to Refresh.
One gesture, many actions. An evolution of Pull to Refresh.

MNTPullToReact MNTPullToReact is an extended evolution of the famous Pull to Refresh interaction. The main idea comes from a unique question: can the

Play BreakOut while loading - A playable pull to refresh view using SpriteKit
Play BreakOut while loading - A playable pull to refresh view using SpriteKit

BreakOutToRefresh Play BreakOut while loading - A playable pull to refresh view using SpriteKit BreakOutToRefresh uses SpriteKit to add a playable min

An easy way to use pull-to-refresh.
An easy way to use pull-to-refresh.

MJRefresh An easy way to use pull-to-refresh 📜 ✍🏻Release Notes: more details Contents New Features Dynamic i18n Switching SPM Supported Swift Chaini

GIFRefreshControl is a pull to refresh that supports GIF images as track animations.
GIFRefreshControl is a pull to refresh that supports GIF images as track animations.

GIFRefreshControl GIFRefreshControl is a pull to refresh that supports GIF images as track animations. Installation You have multiple choices here: Co

Pull-to-refresh animation in UICollectionView with a sticky header flow layout, written in Swift :large_orange_diamond:
Pull-to-refresh animation in UICollectionView with a sticky header flow layout, written in Swift :large_orange_diamond:

ReplaceAnimation Implementation of Zee Young's Dribbble animation (https://dribbble.com/shots/2067564-Replace) Info I really liked Zee Young's animati

An easy way to use pull-to-refresh
An easy way to use pull-to-refresh

CRRefresh an easy way to use pull-to-refresh, If you want to customize its UI style, you just need conform the specified protocol. We will not regular

PullToRefreshSwiftUI - Pull to refresh for SwiftUI
PullToRefreshSwiftUI - Pull to refresh for SwiftUI

PullToRefreshSwiftUI Pull to refresh for SwiftUI. Usage with @State import Swift

Simple way to add parallax header to UIScrollView/UITableView written in Swift.
Simple way to add parallax header to UIScrollView/UITableView written in Swift.

ParallaxHeader Simple way to add parallax header to UIScrollView or it's subclasses. One image view Slider with images Blur vibrant text Blur round ic

Comments
  • multiple time recalculate SVPullToRefreshView layout

    multiple time recalculate SVPullToRefreshView layout

    • (void)layoutForVertical
    • (void)layoutForHorizontal

    this methods call everytime when change contentSize (when we scroll), it kill performance when calculate label size and set text to title or subtitle label.

    • (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if([keyPath isEqualToString:@"contentOffset"]) [self scrollViewDidScroll:[[change valueForKey:NSKeyValueChangeNewKey] CGPointValue]]; else if([keyPath isEqualToString:@"contentSize"]) { [self layoutSubviews];

        self.frame = [SVPullToRefreshView rectForRefreshViewAtPosition:self.position scrollView:self.scrollView];
      

      } else if([keyPath isEqualToString:@"frame"]) [self layoutSubviews];

    }

    opened by sreshetnyak 0
Owner
Hoang Tran
I blog at http://hoangtran.me/ about iOS and stuffs
Hoang Tran
Give pull-to-refresh & infinite scrolling to any UIScrollView with 1 line of code.

SVPullToRefresh + SVInfiniteScrolling These UIScrollView categories makes it super easy to add pull-to-refresh and infinite scrolling fonctionalities

Sam Vermette 4.9k Dec 1, 2022
Animated "Pull To Refresh" Library for UIScrollView.

PullToBounce Animated "Pull To Refresh" Library for UIScrollView. You can add animated "pull to refresh" action to your UIScrollView, UITableView and

Takuya Okamoto 1.9k Dec 5, 2022
LCPullRefresh - Use UIActivityIndicatorView to provide a pull-to-refresh function for UIScrollView.

LCPullRefresh Use UIActivityIndicatorView to provide a pull-to-refresh function for UIScrollView. Requirements iOS 8.0+ Xcode 11.0+ Usage Pull-up refr

LiuChang 7 Aug 5, 2022
Pull to refresh functionality for any ScrollView in SwiftUI!

SwiftUIPullToRefresh Pull to refresh is a common UI pattern, supported in UIKit via UIRefreshControl. (Un)surprisingly, it's also unavailable in Swift

Gordan Glavaš 185 Dec 29, 2022
Animated, customizable, and flexible pull-to-refresh framework for faster and easier iOS development.

KafkaRefresh Animated, customizable, and flexible pull-to-refresh framework for faster and easier iOS development. Report bug · Request feature · 中文文档

H. H. Hsiang 1.2k Dec 11, 2022
ESPullToRefresh is an easy-to-use component that give pull-to-refresh and infinite-scrolling implemention for developers.

ESPullToRefresh is an easy-to-use component that give pull-to-refresh and infinite-scrolling implemention for developers.

Vincent Li 1.7k Jan 8, 2023
✳️ SwiftUI Pull to Refresh (for iOS 13 and iOS 14) package.

Refreshable ✳️ SwiftUI Pull to Refresh (for iOS 13 and iOS 14) package. See complementary article at SwiftUI Pull to Refresh (for iOS 13 and iOS 14).

Geri Borbás 21 Dec 2, 2022
Elastic pull to refresh for iOS developed in Swift

DGElasticPullToRefresh Elastic pull to refresh compontent developed in Swift Inspired by this Dribbble post: Pull Down to Refresh by Hoang Nguyen Tuto

Danil Gontovnik 3.7k Jan 3, 2023
A pull-down-to-refresh control for iOS that plays pong, originally created for the MHacks III iOS app

BOZPongRefreshControl A pull-down-to-refresh control for iOS that plays pong Installation It's on CocoaPods! Put pod 'BOZPongRefreshControl' in your P

Ben Oztalay 885 Dec 12, 2022
Fully customizable pull-to-refresh control inspired by Storehouse iOS app

CBStoreHouseRefreshControl What is it? A fully customizable pull-to-refresh control for iOS inspired by Storehouse iOS app ![screenshot1] (https://s3.

Suyu Zhang 4k Jan 6, 2023