Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make UITableView ignore Safe Area

I have a TableView inside a ViewController. I made the TableView stretch to the View SuperMargings (with constraints) and disabled all SafeArea Inset options but my TableView is still under the SafeArea when I run my project.

How can I make my TableView go full height on iPhones with notch?

like image 928
Mehdi_Mahdloo Avatar asked Dec 17 '19 11:12

Mehdi_Mahdloo


People also ask

How do I disable safe area layout guide?

You can disable safe area layout guide from storyboard for particular view controller. Select View Controller -> File Inspector (first tab) -> Use safe area layout guides (uncheck the checkbox).

What is safe area in iOS?

The safe area represents the portion of your screen that is unobscured by bars and other operating system based content. Safe area is pre-defined by iOS across all Apple devices and is present in Android devices as well.


2 Answers

If you have already pinned tableView to it's superview(not to safeArea) with constraints but tableView still respects safeArea there is property contentInsetAdjustmentBehavior in UIScrollView(UITableView is subclass of UIScrollView as we know) since iOS 11.

This property is UIScrollView.ContentInsetAdjustmentBehavior enum with 4 options. You need to set .never to contentInsetAdjustmentBehavior.

like image 93
Grigory Serebryanyy Avatar answered Oct 28 '22 11:10

Grigory Serebryanyy


What works with any view is to associate the bottom constraint of the table view to the bottom anchor of the root (or parent) view (instead of the SafeArea).

This can be done in the storyboard editor double clicking on the constraint in the right inspector and changing the first item anchor from SafeArea to Superview (or any wanted view).

You can then set the edge insets at will if needed (to avoid content remain partially hidden behind the rounded frame corners or the notch if applying the same procedure to the top anchor)

enter image description here

like image 25
jalone Avatar answered Oct 28 '22 11:10

jalone