Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have full screen UITableView (with header) in iPhone X?

I'm updating my app with Xcode 9 for the iPhone X compatibility. I use auto layout and "Use safe Area Layout Guide" is marked.

I have a header in my UITableView, and, as you can see in the screenshot below, the header view strictly respects the top safe area. The header doesn't follow my tableview top constraint (which is bigger than the safe area)

enter image description here

My tableview constraints :

enter image description here

How can I do to modify my header in order to fill the top of the screen (white area on the screenshot)?

like image 653
cmii Avatar asked Sep 21 '17 12:09

cmii


People also ask

How do you add a footer in tableView?

To create a basic header or footer with a text label, override the tableView(_:titleForHeaderInSection:) or tableView(_:titleForFooterInSection:) method of your table's data source object. The table view creates a standard header or footer for you and inserts it into the table at the specified location.


2 Answers

To achieve this set the top area of the table with respect to the superview instead of safearea.

In viewdidload, write this

if #available(iOS 11.0, *) {
    self.tableView.insetsContentViewsToSafeArea = false;
    self.tableView.contentInsetAdjustmentBehavior = .never;
}
like image 199
Samyak Avatar answered Sep 21 '22 15:09

Samyak


In the size inspector of your tableview, set Content Insets to Never

like image 24
LauraHaworth Avatar answered Sep 18 '22 15:09

LauraHaworth