ZhouJiatao's Blog

去除UITableView分隔线的左边距

解决方法一: 在 Storyboard 设置 Separator Insets

在 Storyboard 中选择 Cell, Attributes inspector -> Separator -> Custom Insets:
Left 填写 0。

解决方法二:设置cell的边距

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// Remove seperator inset
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
// Prevent the cell from inheriting the Table View's margin settings
if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
[cell setPreservesSuperviewLayoutMargins:NO];
}
// Explictly set your cell's layout margins
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}

解决办法三:在cell中模拟出分隔线

将UITableView的separatorStyle属性设置为None,然后在cell的底部加一个View,设置该View的leading、trailing space to superView 为0,高度固定为1或者0.5,最后设置背景色。

参考链接:http://stackoverflow.com/questions/25770119/ios-8-uitableview-separator-inset-0-not-working