0

I have a UITableViewController in a Storyboard that I'm adding as a subview to a lone UIView in a UIViewController, my end goal is to get the UITableView flush up against the status bar so that scrolling goes underneath the status bar (not through it with clashes).

I have configured the lone UIView to have constraints of 0 on both verticals and horizontals but as demonstrated in the image I believe autolayout is then adding the 20px y offset that I am including in the layout. If I remove the 20px y offset (and size the UIView to the whole layout) I end up with the clashing.

20 offset

no offset

Callum Jones
  • 595
  • 4
  • 15

1 Answers1

0

I suggest you to set up your view controller as follows. Create a UIViewController in IB and add a simple UITableView as a subview of its main view. I almost never use the UITableViewController because it has almost no added value but it restricts you in adding subviews to your table view. Now, you position your table view's origin to (0, 20) and set up the top layout constraint of the table view to the top layout guide instead of the superview. Maybe you should open the drop down menu close to the constraint constant value in IB: Align to top layout guide This way your table view will start right under the status bar.

Note however that iOS 7 design guidelines suggest that you would in fact extend the content under the top bars (nav bar and status bar). You should create a 20 points high semi-transparent background png, position it under the status bar, and leave the table view to scroll under the status bar. In this case you should also not forget to check in the "Adjust scroll views inset" option of your view controller.

MrTJ
  • 13,064
  • 4
  • 41
  • 63
  • Thanks! Could you recommend a way to add a refresh control without the use of a UITableViewController? – Callum Jones Feb 21 '14 at 05:46
  • You can try the suggestions of some q&a here in SO, for example http://stackoverflow.com/questions/12497940/uirefreshcontrol-without-uitableviewcontroller Otherwise you either go with your original view structure with container view (in this case set up the constraints of the container view to the top layout guide) or you change the UI and include a semi-transparent background under the status bar - this way you will be also consistent to the UI guidelines of iOS 7. – MrTJ Feb 21 '14 at 08:37
  • Note: if you don't want your content to appear under the status bar only _initially_ (i.e. when the table view is scrolled to the top) it is enough to set up the top content inset of your table view to the height of the status bar. If you use table view controller directly, the view controller does this for you automatically if you check in the "Adjust scroll view insets" option of your vc in interface builder. – MrTJ Feb 21 '14 at 08:43