Skip to content

jmstone617/SVPullToRefresh

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SVPullToRefresh

SVPullToRefresh allows you to easily add pull-to-refresh functionality to any UIScrollView subclass with only 1 line of code. Instead of depending on delegates and/or subclassing UIViewController, SVPullToRefresh extends UIScrollView with a addPullToRefreshWithActionHandler: method as well as a pullToRefreshView property.

Only add pull-to-refresh functionality to your app if it makes sense! Pull to refresh is only appropriate if the pull down gesture is also the one that is used to browse your scroll view. In most cases, pull-to-refresh only makes sense for chronologically-sorted lists of items.

Installation

  • Drag the SVPullToRefresh/SVPullToRefresh folder into your project.
  • Add the QuartzCore framework to your project.
  • #import "SVPullToRefresh.h"

Usage

(see sample Xcode project in /Demo)

Adding pull-to-refresh to a table view can be done with one single line of code:

[tableView addPullToRefreshWithActionHandler:^{
    // refresh data
    // call [tableView.pullToRefreshView stopAnimating] when done
}];

Customization

The SVPullToRefresh view can be customized using the following properties:

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

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];

Showing a “Last Updated” label

If you find it relevant that the user knows the date of the last update, you can set the lastUpdatedDate property of pullToRefreshView:

tableView.lastUpdatedDate = nil; // will display "Last Updated: Never"
tableView.lastUpdatedDate = [NSDate date]; // will display "Last Updated: 4/30/12 11:53 AM"

Under the hood

SVPullToRefresh extends UIScrollView by adding a new public method as well as a dynamic property (thanks @seb_morel!). It uses key-value observing to track the scrollView’s contentOffset, which removes the need for the view to be linked to the UIScrollViewDelegate protocol.

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 permitted the level of abstraction found in SVPullToRefresh.

Hat tip to Loren Brichter for inventing such a great UI mechanism.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 100.0%