Give pull-to-refresh & infinite scrolling to any UIScrollView with 1 line of code.

Overview

SVPullToRefresh + SVInfiniteScrolling

These UIScrollView categories makes it super easy to add pull-to-refresh and infinite scrolling fonctionalities to any UIScrollView (or any of its subclass). Instead of relying on delegates and/or subclassing UIViewController, SVPullToRefresh uses the Objective-C runtime to add the following 3 methods to UIScrollView:

- (void)addPullToRefreshWithActionHandler:(void (^)(void))actionHandler;
- (void)addPullToRefreshWithActionHandler:(void (^)(void))actionHandler position:(SVPullToRefreshPosition)position;
- (void)addInfiniteScrollingWithActionHandler:(void (^)(void))actionHandler;

Installation

From CocoaPods

Add pod 'SVPullToRefresh' to your Podfile or pod 'SVPullToRefresh', :head if you're feeling adventurous.

Manually

Important note if your project doesn't use ARC: you must add the -fobjc-arc compiler flag to UIScrollView+SVPullToRefresh.m and UIScrollView+SVInfiniteScrolling.m in Target Settings > Build Phases > Compile Sources.

  • Drag the SVPullToRefresh/SVPullToRefresh folder into your project.
  • Add the QuartzCore framework to your project.
  • Import UIScrollView+SVPullToRefresh.h and/or UIScrollView+SVInfiniteScrolling.h

Usage

(see sample Xcode project in /Demo)

Adding Pull to Refresh

[tableView addPullToRefreshWithActionHandler:^{
    // prepend data to dataSource, insert cells at top of table view
    // call [tableView.pullToRefreshView stopAnimating] when done
}];

or if you want pull to refresh from the bottom

[tableView addPullToRefreshWithActionHandler:^{
    // prepend data to dataSource, insert cells at top of table view
    // call [tableView.pullToRefreshView stopAnimating] when done
} position:SVPullToRefreshPositionBottom];

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

[tableView triggerPullToRefresh];

You can temporarily hide the pull to refresh view by setting the showsPullToRefresh property:

tableView.showsPullToRefresh = NO;

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;

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

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.

Comments
  • Getting crash when I simulate a memory warning

    Getting crash when I simulate a memory warning

    I have a simple nav baed app. I push the tableviewcontroller that contains pulltorefresh, works as advertised. I pop back to previous view and trigger a memory warning in the simulator. Generally it crashes first try, sometimes second. Commenting out the svpulltorefresh fixes the crash when I trigger the memory warning in the same way. I think a message is being sent to a deallocated obj.

    opened by danielkramer 16
  • dealloc of SVPullToRefresh is not called

    dealloc of SVPullToRefresh is not called

    If one converts the associated sample into a navigation based application with pushing of multiple SVViewController.xib by first adding a button in xib and then pushing the same view controller with tapping of that button. When we go back by tapping on the back button then the memory is not released back. This is probably due to the dealloc of both the view controller as well as SVPullToRefresh is not being called. Also the latest version of SVPullToRefresh also gets crashed when the pull to refresh is in action and one goes back to previous view controller [pop action]

    opened by parvezq 14
  • "Load more" and "Refresh" at the same time

    When the tableView's data source contains a few objects , in other words the data source can't fill full of the tableView then pull to refresh , it will trigger "Load more" and "Refresh" at the same time. http://youtu.be/ntza9pqUmn0

    opened by jxdwinter 9
  • App crashes when adding the SVPullToRefresh view to UITableView

    App crashes when adding the SVPullToRefresh view to UITableView

    I followed the required steps to add the SVPullToRefreshView but it doesn't seems to work. I get following error.

    -[UITableView addPullToRefreshWithActionHandler:]: unrecognized selector sent to instance

    Any idea? Thanks

    opened by jimit 9
  • add SVPullToRefresh to webview

    add SVPullToRefresh to webview

    how can i add your amazing pulltorefresh to a webview? i use it with tableview and it works perfectly....but with webview no....teorically it is a uiview subclass... so?

    Thanks for your work

    opened by fabiosoft 9
  • Fix retain cycle

    Fix retain cycle

    Sam, nice work on this. One problem, which I've found in nearly all PTR implementations, is that you have a retain cycle. I updated the demo code to reference the SVPullToRefresh in a __block variable. Otherwise the controller gets retained when the block is copied, and it will never be released.

    I also made the scrollView property weak instead of strong. The scroll view retains SVPullToRefresh in its subviews array. If SVPullToRefresh also retains the scrollView, neither will ever be released.

    The problem is easy to reproduce in the Allocations instrument. Just tap the launch button, navigate back up, rinse, repeat. You'll see new instances SVController, SVPullToRefresh, and UITableView every time you launch the controller, which are never deallocated.

    opened by twobitlabs 9
  • Added option for pull to refresh from bottom

    Added option for pull to refresh from bottom

    Added -addPullToRefreshWithActionHandler:position: which takes a SVPullToRefreshPosition as second parameter.

    SVPullToRefreshPosition may be either:

    • SVPullToRefreshPositionTop : pull to refresh from the top of the scroll view (the current behavior)
    • SVPullToRefreshPositionBottom : pull to refresh from the bottom of the scroll view

    -addPullToRefreshWithActionHandler: defaults on SVPullToRefreshTop, making this update fully backward compatible.


    Example

    [self.tableView addPullToRefreshWithActionHandler:^{
       // ...
    } position:SVPullToRefreshPositionBottom];
    

    will result in the following behavior

    SVPullToRefresh from bottom

    opened by gabro 8
  • Added DragToLoad and InfiniteScroll handlers

    Added DragToLoad and InfiniteScroll handlers

    This update comes with two additional handlers. DragToLoad allows you to drag past the bottom content and trigger a refresh, similar to PullToRefresh. InfiniteScroll will automatically trigger the refresh when 80% of the content has been scrolled through. Additionally, you can set the sectionLoadLimit and the rowLoadLimit to tell your tableView how much content to load at a time. There is also a loadNextPortion method that will handle incrementing the loaded portions and refreshing your content for you; you just need to update your data source.

    opened by jmstone617 8
  • Add support for setting UIActivityIndicatorView color (iOS 5+)

    Add support for setting UIActivityIndicatorView color (iOS 5+)

    Considering everything else can be customized, I figured it would be nice to add support for setting a custom color for the UIActivityIndicatorView so that user's aren't constrained to either white or gray.

    opened by bdbergeron 7
  • willMoveToSuperview implementation prevents using UIScrollView as a root view in a navigation controller

    willMoveToSuperview implementation prevents using UIScrollView as a root view in a navigation controller

    When the navigation controller pushes on a new controller, the previous view is removed from the hierarchy (but not released) and so willMoveToSuperview gets called. This means that when the user returns to the view, the pullToRefresh instance is re-created and doesn't function as expected.

    My understanding is that an associated object marked "retain" will be released along with the owning object. If this is the case (and I could be mistaken), this pre-emptive removal of the views may be unnecessary.

    I'm running this in iOS6 simulator in Xcode 4.5 GM

    opened by rayh 7
  • Infinite Scrolling is not so friendly.

    Infinite Scrolling is not so friendly.

    Every time the table to it's end, it will load data automatically, I think it's not should be. When table view to end, footer shows with label "Pull to load more...", and when people drag up then the indicator with label "loading..." shows, and load data. I think it's more friendly, I have work on for this for several hours and over my head. So I come here for your help, could you add the function? Thanks.

    opened by RobotAmiee 7
  • Support for Swift Package Manager

    Support for Swift Package Manager

    Swift Package Manager

    • iOS: Open Xcode, File->Swift Packages, search input https://github.com/samvermette/SVPullToRefresh.git, and then select Version Up to Next Major 0.4 < .
    • Or add dependencies in your Package.swift:
    .package(url: "https://github.com/samvermette/SVPullToRefresh.git", .upToNextMajor(from: "0.4")),
    

    Please git tag for this pull request.

    opened by janlionly 0
  • - Fix UIActivityIndicatorView not show when calling startAnimating and hidesWhenStopped is true.

    - Fix UIActivityIndicatorView not show when calling startAnimating and hidesWhenStopped is true.

    Apparently default infinite scrolling view's activity indicator view does not show when enter trigger state. It only shows when enter loading state. This commit fix the problem by manually set hidden property to NO when updating state of infinite scrolling view.

    opened by bsv-hienpham1991 0
  • Mobile Development

    Mobile Development

    Why we can't use direction: SVInfiniteScrollingDirectionTop in swift version 4.2? Can you help to fix error support the problem? I really need your library to load more chat.

    opened by KheangSenghort 0
  • Can I replace the image that is refreshed by the drop-down?

    Can I replace the image that is refreshed by the drop-down?

    Can I replace the image that is refreshed by the drop-down?Can I replace the image that is refreshed by the drop-down? Just like text, you can set the substitution

    opened by chengenyan 0
  • addPullToRefresh for WKWebView

    addPullToRefresh for WKWebView

    Can you use it for a wkwebview?

    Thank you

    I try this but don't work

    webview?.scrollView.addPullToRefresh {
                                        self.getRequest(url_view: self.url_view)
    }
    
    opened by SalvatoreAD 0
Easily add vertical and horizontal pull to refresh to any UIScrollView. Can also add multiple pull-to-refesh views at once.

This is a fork from the famous SVPullToRefresh pod with 2 additional functionalities: Can add multiple pull-to-refresh views into one single UIScrollV

Hoang Tran 42 Dec 28, 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
Custom animated pull-to-refresh that can be easily added to UIScrollView

PullToMakeSoup Custom animated pull-to-refresh that can be easily added to UIScrollView Check this article on our blog to know more details about anim

Yalantis 1.9k Dec 17, 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
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
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

Peiwei 55 Aug 21, 2022
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

Mention 777 Nov 20, 2022
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

Dominik Hauser 2.5k Dec 29, 2022
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

M了个J 13.7k Jan 6, 2023
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

Kevin Delannoy 163 Oct 4, 2022
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

Alex Türk 957 Sep 13, 2022
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

CRAnimation 957 Dec 13, 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
PullToRefreshSwiftUI - Pull to refresh for SwiftUI

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

Dmitry Kononchuk 1 Feb 28, 2022
✳️ 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
PullToRefresh extension for all UIScrollView type classes with animated text drawing style

PullToRefreshCoreText PullToRefresh extension for all UIScrollView type classes with animated text drawing style Demo Install Manual Copy the files in

Cem Olcay 314 Dec 3, 2022