TableView and home indicator on iPhone X

I use both UITableViewController and UITableView in one project.

An UITableView in the UITableViewController imposes a home indicator on the iPhone X. But the UITableView in the UIViewController does not impose a home indicator on the iPhone X. Should I match? And which one is correct when I look at a safe area?

ex

UITableViewController

UITableView on UIViewController

+5
source share
3 answers

You can continue to use the UITableView in the standard UIViewController . Just set the auto layout so that the bottom of the table is flush with the bottom of the supervisor (not the field). Then set the insetsContentViewsToSafeArea tableview property to true

Swift:

 if #available(iOS 11.0, *) { tableView.insetsContentViewsToSafeArea = true; } 

Objective-C:

 if (@available(iOS 11.0, *)) { [tableView setInsetsContentViewsToSafeArea:YES]; } 
+3
source

This is what worked for me in iOS 12 :

I tried to set insetsContentViewsToSafeArea , but it did not work, although it set me on the right path. What fixed it for me was setting "Inset Content" in the nib / storyboard to "Never" (in the code, this is the property contentInsetAdjustmentBehavior ).

Explanation: It appears that for iPhoneX and above, the system automatically adds a bottom indent for table views, so that the content goes beyond the home indicator.

+2
source

This is because the table view in the UITableViewController is the root view. It will expand to full screen. But you can make restrictions for the bottom layout for representing the table in the UIViewController. This way you can use the UIViewController. Or you can set the insert content in the UITableViewController.

+1
source

Source: https://habr.com/ru/post/1272865/


All Articles