How can I make a UITableViewCell with custom style inset from the safe area of the device screen when it is part of the view hierarchy
UINavigationController > UIViewController > UIView > UITableView > UITableViewCell
? My UITableViewCell left side is getting cut off by the camera notch.Setting the iOS 11
contentInsetAdjustmentBehavior
and insetsContentViewsToSafeArea
methods do not work when I have a combination of both custom layout UITableViewCell (not one of the Basic/Detail view styles) and am using the UITableViewCell in a view that is itself within a UINavigationController. And those values should default to YES.preservesSuperviewLayoutMargins
which defaults to NO.A couple of the behaviors
Setting the view hierarchy as
UIViewController > UIView > UITableView > UITableViewCell. UIViewController
is the entry point of the Storyboard. (below)
- The custom UITableViewCell is inset from the horizontal safe area correctly like normal.
- Setting the view hierarchy as
. UINavigationController is the entry point of the Storyboard with UIViewController as the root view controller to the navigation controller.UINavigationController > UIViewController > UIView > UITableView > UITableViewCell
Only the UITableView requires
to inset the Basic/Detail style UITableViewCell from the safe area.preservesSuperviewLayoutMargins = YES
- Setting the view hierarchy as
. UINavigationController is the entry point of the Storyboard with UIViewController as the root view controller to the navigation controller.UINavigationController > UIViewController > UIView > UITableView > UITableViewCell
- Unable to inset the default style UITableViewCell from the safe area.
- In the below screenshot the
with a custom layout UITableViewCell but the cell fails to properly inset with safe area as seen in the cutoff simulator at the bottom.UITableView.preservesSuperviewLayoutMargins = YES
My layout constraints for the custom UITableViewCell are shown below. As seen Interface Builder simulates the correct inset but the actual simulator run does not inset the cell.
The view hierarchies in #2 and #3 are the same with the only difference being the use of a custom layout UITableViewCell vs the default Basic/Detail style.
I've tried setting
preservesSuperviewLayoutMargins = YES
on every view in the hierarchy and it makes not difference for getting the custom UITableViewCell to inset. I made a simple test project https://drive.google.com/file/d/1FJJ2f91pgm2QtBjlJMZZXoaPn2nSkOsX/view?usp=sharing demonstrating the inset issue between default Basic and custom style cells in the described view hierarchy.I can't be the only one testing a custom UITableViewCell on a landscape iPhone X/11. How can I get the table cell contents to inset correctly from the device safe area? Thanks.