ChatGPT解决这个技术问题 Extra ChatGPT

How to fix UITableView separator on iOS 7? [duplicate]

This question already has answers here: Is there a way to make UITableView cells in iOS 7 not have a line break in the separator? (17 answers) Closed 8 years ago.

UITableView draws with ragged lines on iOS 7:

https://i.stack.imgur.com/OE69H.png

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


s
s1m0n

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];
}

Please correct answer to: ` if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) { [tableView setSeparatorInset:UIEdgeInsetsZero]; } `
In which method should I write this line? Doesn't work for me.
This did not work for me. But this worked : if ([self.tableView respondsToSelector:@selector(setSeparatorStyle:)]) { [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; }
This answer didn't work for me in iOS8. This did...tableView.layoutMargins = UIEdgeInsetsZero; and in your cellForRowAtIndexPath method: cell.layoutMargins = UIEdgeInsetsZero;
@Tim Awesome comment.Please post it as an answer as this is the only straightforward method working in iOS8.
T
Tarek Hallak

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:

https://i.stack.imgur.com/6esYR.png

https://i.stack.imgur.com/ViW4c.gif


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.
Hope there will be more gif like this one in stack overflow
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.
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.
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/…