0

I just bought a book and learn programming IOS in Swift. I want to create a table view list like snapchat: enter image description here

Then I set the all of the constrain of the UITableView to enter image description here0:

However, there is still a margin on left of the table, why?

enter image description here

dramasea
  • 3,370
  • 16
  • 49
  • 77
  • 3
    Possible duplicate http://stackoverflow.com/questions/25762723/remove-separatorinset-on-ios-8-uitableview-for-xcode-6-iphone-simulator – Artrmz May 08 '15 at 13:43

2 Answers2

5

Search for Separator inset in interface builder after clicking on the UITableView

Before

And change it to Custom. Now you can set the Left Inset to 0

After

Objective-C

in viewDidLoad

[tableView setSeparatorInset:UIEdgeInsetsZero];

Add Following Code in cellForRowAtIndexPath:

if ([cell respondsToSelector:@selector(preservesSuperviewLayoutMargins)]){
    cell.layoutMargins = UIEdgeInsetsZero;
    cell.preservesSuperviewLayoutMargins = false;
}

Swift

if ([UITableView instancesRespondToSelector:@selector(setLayoutMargins:)]) {
    [[UITableView appearance] setLayoutMargins:UIEdgeInsetsZero];
    [[UITableViewCell appearance] setLayoutMargins:UIEdgeInsetsZero];
    [[UITableViewCell appearance] setPreservesSuperviewLayoutMargins:NO];
}
Ashish Kakkad
  • 23,586
  • 12
  • 103
  • 136
2

As @Ashish Kakkad pointed out, it's about the SeparatorInsets, I just wanted to add here, that you can also set them in Storyboard, you don't have to do this in code.

Search for Separator inset in interface builder after clicking on the table view Before

And change it to Custom. Now you can set the Left Inset to 0

After

Nils Ziehn
  • 4,118
  • 6
  • 26
  • 40