13

Something is up with our table view cell separators on the iPhone 6 Plus. I created a blank test project with a custom cell with only one label and a 15pt constraint to the leading edge.

iPhone 5S

Label and separator are 30 px (15pt) from the leading edge. All is good.

iPhone 5S

iPhone 6 Plus

Label is 48 px (15pt) from the leading edge and the separator is 60px (20pt) from the leading edge.

iPhone 6 Plus

If i log the tableView.separatorInset it's 15pt on the iPhone 5S and 20pt on the 6 Plus. Setting the inset to 15 on the 6 Plus manually doesn't work.

Please send help.

Maciej Swic
  • 11,139
  • 8
  • 52
  • 68

5 Answers5

6

Override layoutMargins method in your custom cell class.

 - (UIEdgeInsets)layoutMargins
{
    return UIEdgeInsetsMake(0, 15, 0, 0);
}
Vidyalaxmi
  • 309
  • 1
  • 5
  • What's better way to do this without hard coding number? – Sam Feb 15 '15 at 05:02
  • A better way is to disable separator and add a custom view as separator. – Vidyalaxmi Jan 11 '16 at 06:46
  • For the proper way to do it, check out [this post](http://stackoverflow.com/questions/27420888/uitableviewcell-with-autolayout-left-margin-different-on-iphone-and-ipad). The reason why that is the proper way is because it respects the larger left margin of a larger device like 6 Plus or iPad. Apple set the margin to be larger for a reason, so it looks better, and the apps should respect that. – Eric Jan 23 '16 at 19:49
2

If you are using a Storyboard, select the Table View attributes inspector. Change the

Separator Inset

to

Custom

and leave the default left margin as 15.

Daniel
  • 8,794
  • 4
  • 48
  • 71
  • For IOS 9, this solution worked for me. I was using a custom cell that contained a label with a 15pt constraint to the leading edge. The 15pt constraint worked great with all iPhones except with the iPhone 6+ & iPad (the label wasn't aligned with the tableview's separator inset). This solution fixed the problem though. Thanks! – xNightxOwl Sep 06 '15 at 02:10
  • Works also on iOS 8. Most easy solution for me. – Tuslareb Feb 29 '16 at 11:32
1

Not a perfect solution, but it worked for me.

@IBOutlet weak var leftViewLeadingConstraint: NSLayoutConstraint!

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()
    switch UIScreen.mainScreen().scale {
    case 2:
        leftViewLeadingConstraint.constant = 7.0
    case 3:
        leftViewLeadingConstraint.constant = 11.0
    default:
        assertionFailure("Error: wrong scale value")
    }
}
Konstantin Cherkasov
  • 3,243
  • 2
  • 18
  • 22
  • I don't know why this answer didn't get votes. It worked perfectly for me! I adjusted the leading edge constraint in the layoutSubviews method in my UITableViewCell subclass if the scale is 3, and in the Storyboard, I specified the leading edge constraint to have a value of 12 (I think 11 is wrong) if the size class is Regular width x Any height. – Blip Mar 30 '15 at 22:59
1

I fixed by this solution: http://qiita.com/mono0926/items/42f7a344b39e946abfe2

Get tableView.separatorInset.left value when viewDidLayoutSubviews called.

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    notificationLabelLeft.constant = tableView.separatorInset.left
}
mono
  • 4,340
  • 3
  • 21
  • 49
0

Just make this option of the table to false and it will work the same on all devices, especially on iPad.

cellLayoutMarginsFollowReadableWidth = false
invoodoo
  • 3,905
  • 1
  • 18
  • 16