Skip to content

Instantly share code, notes, and snippets.

@AlexHedley
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save AlexHedley/feef1785d533d3960a22 to your computer and use it in GitHub Desktop.

Select an option

Save AlexHedley/feef1785d533d3960a22 to your computer and use it in GitHub Desktop.
Pull to Refresh
#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]
- (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];
}
@AlexHedley

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment