iOS cell分割线不能占据整个屏幕宽度解决方案

来源:互联网 发布:找一份网络兼职 编辑:程序博客网 时间:2024/06/05 09:07

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

调整之后效果:
这里写图片描述

阅读全文
0 0
原创粉丝点击