Matching left alignment of custom & standard UITableViewCell types Matching left alignment of custom & standard UITableViewCell types ios ios

Matching left alignment of custom & standard UITableViewCell types


I was having the same issue but the other answer couldn't help me as I was using static cells in UITableViewController. After a few trial-and-errors, I finally found a way to solve the separatorInset issue on iPhone 6+ without a single line of code.

enter image description here

I simply align the left edge of the UILabel with value of 0 [Content View (current distance = 0)] from the left margin. And also change the UILabel's X position to get 0. (For my case, in Interface Builder, margin was 7, UILabel's X = 8). The alignment works well on iPhone 4S, 5S, 6 and 6+.

EDIT: This changed in XCode 7. Additional step: Set "Preserve Superview Margins" of the respective cell's TableViewCell and its contentView to TRUE or check it in IB -> Size Inspector. Refer to @tebs1200's answer.

Hope this helps.


You can implement the solution suggested by Mark purely in the storyboard:

  1. Make sure the custom cell is selected.

    Table View Cell selected in view tree

  2. Make sure Preserve Superview Margins is selected in the Size inspector

    'Preserve Superview Margins' selected in the Size inspector

  3. Now select the cell's Content View

    enter image description here

  4. Make sure Preserve Superview Margins is selected here too (see image in step 2.)

  5. Select the label (or other view) in your custom prototype cell.
  6. Constrain it's left edge 0 pixels from the margin.

    enter image description here


What worked for me was adding these 2 lines to my custom UITableViewCell implementation:

self.preservesSuperviewLayoutMargins = YES;self.contentView.preservesSuperviewLayoutMargins = YES;// ... add test view to content view...

Then I used Auto Layout with the default spacing:

[self.contentView addConstraints:[NSLayoutConstraint   constraintsWithVisualFormat:@"H:|-[testView]-|" options:0 metrics:nil    views:@{@"testView":testLabel}]];[self.contentView addConstraints:[NSLayoutConstraint   constraintsWithVisualFormat:@"V:|-[testView]-|" options:0 metrics:nil    views:@{@"testView":testLabel}]];