Last active
August 29, 2015 14:15
-
-
Save AlexHedley/feef1785d533d3960a22 to your computer and use it in GitHub Desktop.
Pull to Refresh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (void)viewDidLoad { | |
| [super viewDidLoad]; | |
| [self setupRefresh]; | |
| ... | |
| } | |
| - (void)setupRefresh { | |
| UIRefreshControl *refresh = [[UIRefreshControl alloc] init]; | |
| refresh.tintColor = UIColorFromRGB(0x2194D3); | |
| refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"]; | |
| [refresh addTarget:self action:@selector(refreshView:) forControlEvents:UIControlEventValueChanged]; | |
| self.refreshControl = refresh; | |
| } | |
| - (void)refreshView:(UIRefreshControl *)refresh { | |
| [self getData]; | |
| refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Refreshing data..."]; | |
| // custom refresh logic would be placed here... | |
| NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; | |
| [formatter setDateFormat:@"MMM d, h:mm a"]; | |
| NSString *lastUpdated = [NSString stringWithFormat:@"Last updated on %@", [formatter stringFromDate:[NSDate date]]]; | |
| refresh.attributedTitle = [[NSAttributedString alloc] initWithString:lastUpdated]; | |
| [refresh endRefreshing]; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://www.intertech.com/Blog/ios-6-pull-to-refresh-uirefreshcontrol/