Make UITableView ignore Safe Area
Asked Answered
E

2

10

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?

Ermey answered 17/12, 2019 at 11:16 Comment(1)
How did you set AutoLayout? Using Constraint in storyboard or via progarmatically ?Byelorussian
S
28

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.

Steamboat answered 17/12, 2019 at 11:41 Comment(0)
A
3

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

Aircraftman answered 17/12, 2019 at 11:35 Comment(1)
Can you show the view hierarchy in the storyboard (the same applies when done programmatically tho)?Aircraftman

© 2022 - 2024 — McMap. All rights reserved.