iOS系统默认的cell分割线并不会占满整个屏幕的宽度,但是有些PM设计的cell分割线是要求占满的;
几种解决方案根据自己的需求选择:
1.自定义分割线
//取消系统自带的分割线
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
// 自定义cell的时候创建一个分割线添加到cell底部
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(cell.frame)-1, cell.frame.size.width, 1)];
line.backgroundColor = [UIColor groupTableViewBackgroundColor];
[cell.contentView addSubview:line];
2.系统属性(iOS8以后)
//清空tableView内边距
self.tableView.separatorInset = UIEdgeInsetsZero;
//如果上面没有效果,在清空cell的约束边缘
self.layoutMargins = UIEdgeInsetsZero;
3.万能方式(重写cell的setFrame)
// 1.取消系统自带分割线
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//2.把tableView背景色设置为分割线的背景色
self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
//3.重写cell的setFrame
- (void)setFrame:(CGRect)frame
{
//根据需求去调整分割线的宽度
frame.size.height -= 1;
// 真正去给cell赋值
[super setFrame:frame];
}
调整之后效果: