在做项目中,自定义cell的时候,分割线离左边大概有15分距离。除非让分割线UITableViewCellSeparatorStyleNone,然后自定义一条线。
现在,如果想用系统自带的分割线。那么,下面就是解决分割线不贴边的方法,直接复制代码就行,不用纠结别的。
在初始化tableView的时候复制这段代码。
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 这个代理方法中复制这段代码
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
[cell setSeparatorInset:UIEdgeInsetsZero];
}
运行就可以了。