213

UITableView draws with ragged lines on iOS 7:

enter image description here

How to fix it? The line between cells should be on the full width of the screen.

0

2 Answers 2

488

UITableView has a property separatorInset. You can use that to set the insets of the table view separators to zero to let them span the full width of the screen.

[tableView setSeparatorInset:UIEdgeInsetsZero];

Note: If your app is also targeting other iOS versions, you should check for the availability of this property before calling it by doing something like this:

if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
    [tableView setSeparatorInset:UIEdgeInsetsZero];
}
15
  • 6
    Please correct answer to: ` if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) { [tableView setSeparatorInset:UIEdgeInsetsZero]; } `
    – Dmitry
    Sep 12, 2013 at 20:15
  • 1
    In which method should I write this line? Doesn't work for me.
    – Kaptain
    Sep 26, 2013 at 9:44
  • 2
    This did not work for me. But this worked : if ([self.tableView respondsToSelector:@selector(setSeparatorStyle:)]) { [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; }
    – anasaitali
    Oct 8, 2013 at 13:25
  • 45
    This answer didn't work for me in iOS8. This did...tableView.layoutMargins = UIEdgeInsetsZero; and in your cellForRowAtIndexPath method: cell.layoutMargins = UIEdgeInsetsZero;
    – Tim
    Sep 30, 2014 at 23:43
  • 1
    @Tim Awesome comment.Please post it as an answer as this is the only straightforward method working in iOS8.
    – madLokesh
    Mar 20, 2015 at 10:31
236

This is default by iOS7 design. try to do the below:

[tableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];

You can set the 'Separator Inset' from the storyboard:

enter image description here

enter image description here

16
  • 11
    For other users, note that the default value of this is "Default". You need to change it to "Custom" in order to be able to edit the inset values.
    – Dj S
    Oct 4, 2013 at 5:22
  • 5
    Hope there will be more gif like this one in stack overflow
    – John
    Jul 14, 2014 at 16:36
  • 33
    This acts weird in iOS 8. I set it to 0 but nothing changed. But I increased it to 50, it worked! I tried setting it to 0 from code too but no. Can anyone confirm this? I'm on Xcode 6 beta 4.
    – Isuru
    Jul 31, 2014 at 7:02
  • 21
    Im working in Xcode6 beta 4 and when setting separator insets to 0 for both left and right there is still a small gap on the left.
    – MrOli3000
    Aug 25, 2014 at 7:20
  • 9
    I can't post the ios 8/xcode 6 solution because the question is locked. But you can find a solution for ios 8/xcode 6 here: stackoverflow.com/questions/25770119/…
    – Mike S
    Oct 21, 2014 at 23:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.