设置UITableView的单元格分割线离屏幕左右的距离为0

来源:互联网 发布:智能开关 app 源码 编辑:程序博客网 时间:2024/05/16 07:45

在开发中,有时候为了界面的美观,需要表示图的分割线左右间距为0,即呈现下面的效果


有时候就直接取消显示表视图的分割线,然后在单元格内直接添加一条直线,这样也能满足要求,还有一种方法是改变表视图内部的分割线的偏移量来实现,具体代码如下:

if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {        [_tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];    }        if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {        [_tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];    }
//代理方法-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {        [cell setSeparatorInset:UIEdgeInsetsZero];    }        if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {        [cell setLayoutMargins:UIEdgeInsetsZero];    }}

这样,就实现了单元格分割线的满格显示了。

0 0