I am using both UITableViewController
and UITableView
in one project.
An UITableView
in an UITableViewController
overlays the home indicator on iPhone X. But an UITableView
in an UIViewController
doesn't overlay the home indicator on iPhone X. Should I fit one? And which one is correct when I consider about safe area?
ex
You can continue to use a UITableView
on a standard UIViewController
. Just set auto layout so the bottom of the tableview is flush with the bottom of the superview (and not the margin). Then set the insetsContentViewsToSafeArea
property of the tableview to true
Swift:
if #available(iOS 11.0, *) {
tableView.insetsContentViewsToSafeArea = true;
}
Objective-C:
if (@available(iOS 11.0, *)) {
[tableView setInsetsContentViewsToSafeArea:YES];
}
This is what worked for me, in iOS 12 :
I tried setting insetsContentViewsToSafeArea
but that didn't work, although it set me on the right path. What fixed it for me was setting the "Content Insets" in the nib/storyboard to "Never" (in the code, that property is contentInsetAdjustmentBehavior
).
Explanation: It seems that, for iPhoneX and above, the system automatically adds some bottom padding for table views so that the content goes above the home indicator.
This is because table view in UITableViewController is root view. It will extend to full screen. But you can make constraints to bottom layout guide for table view in UIViewController. So you can use UIViewController. Or you can set content insets in UITableViewController.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.