1

On iPhone 6s, when I set cell separator line left inset to 14, is show 15, I think that is because it set preservesSuperviewLayoutMargins = true by default.

But from apple doc: "The side margins vary depending on how and where the controller is presented, but can be either 16 or 20 points(depending on the device). You cannot change these margins."

When I add a view to the side of root view by auto layout, and set preservesSuperviewLayoutMargins = true, the distance from the edge of root view to the view I added is 16 on iPhone 6s, so it is not aligned to the left edge of the table view. How can UITableViewCell use preservesSuperviewLayoutMargins = true, and the side margins is 15, not 16?

zgjie
  • 2,099
  • 2
  • 21
  • 32

1 Answers1

1

After some logs, I know why, that is because:

tableView.preservesSuperviewLayoutMargins = false

And the table View's layoutMargins is (8, 15, 8, 15) on iPhone 6; (8, 20, 8, 20) on iPhone 6 Plus.

On apple documents, it is only said: "The default margins are 8 points on each side. You can modify these margins based on your app’s needs."

But the table view's layoutMargins is (8,8,8,8) on viewDidLoad(), then change to (8, 15, 8, 15) later on iPhone 6.

This is very confusing when I want to add a view left align to the table view, and the subview's left edge left align to table view separator line. I had to update the view like this:

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    totalBar.preservesSuperviewLayoutMargins = tView.preservesSuperviewLayoutMargins
    totalBar.layoutMargins = tView.layoutMargins
}

So that I don't need to hardcode the margin values for 6 and 6 Plus, and for even Apple change the value in future.

zgjie
  • 2,099
  • 2
  • 21
  • 32