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
:
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/orUIScrollView+SVInfiniteScrolling.h
Usage
(see sample Xcode project in /Demo
)
Adding Pull to Refresh
or if you want pull to refresh from the bottom
If you’d like to programmatically trigger the refresh (for instance in viewDidAppear:
), you can do so with:
You can temporarily hide the pull to refresh view by setting the showsPullToRefresh
property:
Customization
The pull to refresh view can be customized using the following properties/methods:
You can access these properties through your scroll view's pullToRefreshView
property.
For instance, you would set the arrowColor
property using:
Adding Infinite Scrolling
If you’d like to programmatically trigger the loading (for instance in viewDidAppear:
), you can do so with:
You can temporarily hide the infinite scrolling view by setting the showsInfiniteScrolling
property:
Customization
The infinite scrolling view can be customized using the following methods:
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
.