I've created a UITableView which I want to scroll underneath my semi-transparent black status bar. In my XIB, I just set the table view's y position to -20 and it all looks fine.
Now, I've just added a pull-to-refresh iOS6 UIRefreshControl which works however, because of the -20 y position, it drags from behind the status bar. I'd like it's "stretched to" position to be under the status bar rather than behind.
It makes sense why it's messing up but there doesn't seem to be any difference changing it's frame and the tableview's content insets etc don't make a difference.
The docs suggest that once the refreshControl has been set, the UITableViewController takes care of it's position from then on.
Any ideas?
Try this:
This will move UIRefreshControll down for 44 points;
The current upvoted answer does not play well with the fact you pull the component down (as Anthony Dmitriyev pointed out), the offset is incorrect. The last part is to fix it.
Either way: subclass the
UIRefreshControl
with the following method:I found the overriding of the layoutsubviews in the other answers did more than change the frame, they also change the behaviour (the control started sliding down with the content). To change the frame but not the behaviour I did this:
}
You can subclass the
UIRefreshControl
and implementlayoutSubviews
like so:It takes tableView's
contentInset
into account, but you can changetopContentInset
variable to whatever value you need and it will handle the rest.I hope the code is documented enough to understand how it works.
UIRefreshControl
always sits above the content in yourUITableView
. If you need to alter where the refreshControl is place, try altering the tableView's topcontentInset
. TheUIRefreshControl
takes that into account when determining where it should be positioned.Just subclass the UIRefreshControl and override layoutSubviews like this: