214

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.

Dmitry
  • 14,306
  • 23
  • 105
  • 189

2 Answers2

489

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];
}
s1m0n
  • 7,825
  • 1
  • 32
  • 45
  • 6
    Please correct answer to: ` if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) { [tableView setSeparatorInset:UIEdgeInsetsZero]; } ` – Dmitry Sep 12 '13 at 20:15
  • 1
    In which method should I write this line? Doesn't work for me. – Kaptain Sep 26 '13 at 09:44
  • You can call this method on your table view in `viewDidLoad`. If your table view is create programmatically, you should create an IBOutlet in order to get a reference to it. – s1m0n Oct 01 '13 at 15:09
  • @s1m0n any idea how you also remove the padding to the left and right of cell.imageViews in in iOS7? If you look at the 1st questions image I have the same issue..I tried setting the imageViews frame but made no difference? – Alex McPherson Oct 02 '13 at 08:29
  • 2
    This did not work for me. But this worked : ```if ([self.tableView respondsToSelector:@selector(setSeparatorStyle:)]) { [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; }``` – anasaitali Oct 08 '13 at 13:25
  • it's working very successful. I have white line on tableview , now ı haven't . thank a lot :) – Erhan Demirci Oct 09 '13 at 11:23
  • note to others: doesn't work from initWithStyle - I popped it in viewDidLoad and it works great – Sam Nov 26 '13 at 10:35
  • Note that if you have written your own UITableViewCell subclass, you might have to do the following in layoutSubviews: self.separatorInset = UIEdgeInsetsZero; – Willster Dec 20 '13 at 11:57
  • It's working only for first "collection" of cells. When you add new cell there, separators are "free to go" – Alex Sorokoletov Jun 25 '14 at 02:55
  • For Xamarin IOS C# it will be tableView.SeparatorInset = UIEdgeInsets.Zero; – kiran Sep 02 '14 at 09:13
  • 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 '14 at 23:43
  • How this isn't default behavior BAFFLES me. Looking for an iOS 8 solution, as neither this nor the comment directly above mine seems to be working. – Ruben Martinez Jr. Oct 05 '14 at 18:44
  • 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: http://stackoverflow.com/questions/25770119/ios-8-uitableview-separator-inset-0-not-working – Mike S Oct 21 '14 at 23:29
  • I can't post the Swift version, working and tested on iOS 7 and 8, because the question is locked. But you can find this solution here: http://bit.ly/1HzXBis – King-Wizard Dec 24 '14 at 08:59
  • 1
    @Tim Awesome comment.Please post it as an answer as this is the only straightforward method working in iOS8. – madLokesh Mar 20 '15 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

Tarek Hallak
  • 18,422
  • 7
  • 59
  • 68
  • 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 04 '13 at 05:22
  • [cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)]; is probably a better idea – AmiiQo Jun 10 '14 at 08:17
  • 5
    Hope there will be more gif like this one in stack overflow – John Jul 14 '14 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 '14 at 07:02
  • Okay I tested this in both iOS 7 and iOS 8. Here are the results - [iOS 7](http://i.imgur.com/czINe0t.png), [iOS 8](http://i.imgur.com/2xgOd3d.png). As you can see in iOS 7 it works as expected but there is a glitch in iOS 8, the custom inset is applied only to the cell with no text. – Isuru Jul 31 '14 at 07:37
  • I see the same thing @Isuru. Hopefully it will be addressed in beta 5. Did you file a bug report? – Jordan H Aug 01 '14 at 19:44
  • @Joey Yeah, hope so. And yes, I did file a bug. – Isuru Aug 01 '14 at 20:41
  • I have posted a workaround [here](http://stackoverflow.com/a/25088632/1077789). – Isuru Aug 01 '14 at 21:02
  • 2
    Didn't work for me either, in iOS 8. – rounak Aug 20 '14 at 11:16
  • 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 '14 at 07:20
  • 1
    Working in xcode6 beta6 and iOS 7 and there is a gap on the left whatever I do - storyboard or code. – amergin Aug 27 '14 at 14:20
  • 3
    still happening on the iOS 8 GM build. I fixed it by adding a a UIView with height of 1px to the bottom of my cells. To mimic default colour colours I made the view's colour white and alpha = 0.2 http://puu.sh/bvFnU/a64f1e52f5.png – gabe.roze Sep 12 '14 at 06:39
  • 3
    I concur, doctor. iOS8 doesn't honor UIEdgeInsetsZero :( – cleverbit Sep 25 '14 at 10:38
  • any solutions for xcode 6.0.1 ? – kozla13 Oct 10 '14 at 10:47
  • 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: http://stackoverflow.com/questions/25770119/ios-8-uitableview-separator-inset-0-not-working – Mike S Oct 21 '14 at 23:30
  • 1
    Doesn't work on iOS9/XCode 7 either. – JRam13 Apr 05 '16 at 21:12