Give a top inset to UIRefreshControl

Tancrede Chazallet picture Tancrede Chazallet · Oct 21, 2013 · Viewed 7.1k times · Source

I use an UIRefreshControl like it (without an UITableViewController) :

UIRefreshControl *refreshControl = [UIRefreshControl new];
[refreshControl addTarget:self action:@selector(viewDidBeginRefreshing:) forControlEvents:UIControlEventValueChanged];
[self.table addSubview:refreshControl];

Problem is the refresh wheel is positioned below the UINavigationController's translucent bar (ios7). There is only a few topic on this problem on StackOverflow. And they didn't bring any valuable solution to me.

What I wish is to make my UIRefreshControl's y position 80px down for example.

Note : I know it's not recommended to use UIRefreshControl outside an UITableViewController. So no need to warn about it.

Answer

Tancrede Chazallet picture Tancrede Chazallet · Oct 22, 2013

I found a solution, very simple, not so clean but works like a charm.

Just need to put the refresh control in another subview which is set down.

UIView *refreshView = [[UIView alloc] initWithFrame:CGRectMake(0, 80, 0, 0)];
[self.table addSubview:refreshView];

UIRefreshControl *refreshControl = [UIRefreshControl new];
[refreshControl addTarget:self action:@selector(viewDidBeginRefreshing:) forControlEvents:UIControlEventValueChanged];
[refreshView addSubview:refreshControl];