iOS7 and UIRefreshControl in UIViewController (with UITableView)
A UIRefreshControl object provides a standard control that can be used to initiate the refreshing of a table view’s contents.
If you are into a UITableViewController, you can use the refreshControl property like explained here.
But how can you use it programmatically? How can you change the tintColor? How can you change the attributeTitle color? If you wanna use the UIRefreshControl into a UIViewController that has a UITableView inside... and if you are using iOS7... you can do it writing the code below.
How you can see, the best solution is to put the UIRefreshControl into a UIView, so the UIRefreshControl not goes under the top bar.
@interface MyViewController () { UIRefreshControl *refreshControl; } @property (weak, nonatomic) IBOutlet UITableView *tableView; @end @implementation MyViewController - (void)viewDidLoad { [super viewDidLoad]; UIView *refreshView = [[UIView alloc] initWithFrame:CGRectMake(0, 55, 0, 0)]; [self.tableView insertSubview:refreshView atIndex:0]; //the tableView is a IBOutlet refreshControl = [[UIRefreshControl alloc] init]; refreshControl.tintColor = [UIColor redColor]; [refreshControl addTarget:self action:@selector(reloadDatas) forControlEvents:UIControlEventValueChanged]; /* NSMutableAttributedString *refreshString = [[NSMutableAttributedString alloc] initWithString:@"Pull To Refresh"]; [refreshString addAttributes:@{NSForegroundColorAttributeName : [UIColor grayColor]} range:NSMakeRange(0, refreshString.length)]; refreshControl.attributedTitle = refreshString; */ [refreshView addSubview:refreshControl]; } -(void)reloadDatas { //update here... [refreshControl endRefreshing]; } @end
That's all.













