解决UITableViewCell左侧分割线有空白的问题

来源:互联网 发布:辛全生淘宝工具全集 编辑:程序博客网 时间:2024/05/01 22:12

ios7中,UITableViewCell左侧会有默认15像素的空白。设置setSeparatorInset:UIEdgeInsetsZero 能将空白去掉。

ios8中,setSeparatorInset:UIEdgeInsetsZero 的设置已经不起作用了。

 

工程中添加如下代码便可解决:

self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

-(void)viewDidLayoutSubviews

{

    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {

        [self.tableView setSeparatorInset:UIEdgeInsetsZero];

    }

 

    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {

        [self.tableView setLayoutMargins:UIEdgeInsetsZero];

    }

}

 

-(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