0

In a UITableView (plain style) with dynamic prototype cells and mostly standard headers and footers, I had to replace one header with a custom view.

This was easily done by creating a UIView in the storyboard inside the affected table view (next to, but outside of the cell prototypes), connecting it to an outlet and returning that outlet in the viewForHeaderInSection method.

This view has some content, of course, and I want to left-align it with all the rest. The standard margin however is different for iPhone/iPad and it also changes with orientation.

From which property can I retrieve the currently needed left margin?

Setting it programmatically via an outlet to a suitable auto-layout constraint is easy again, but where do I get the value to use from?

(This question is similar to Matching left alignment of custom & standard UITableViewCell types, but for headers, not cells)

LPG
  • 384
  • 2
  • 12

1 Answers1

0

The value obtained from

self.tableView.separatorInset.left

seems to do the trick. The auto-layout constraint for the margin should be set in the viewForHeaderInSection method. Call self.tableView.reloadData() when you detect device rotation to keep it up to date.

LPG
  • 384
  • 2
  • 12