iOS 让tableView分割线从边框顶端开始

来源:互联网 发布:显卡更新驱动负优化 编辑:程序博客网 时间:2024/06/04 19:06

1.直接把tableView设置成self.tableView.separatorStyle =UITableViewCellSeparatorStyleNone.然后自定义cell那里自己加一个view,高度为1,颜色自己设置。

2.添加这两个方法 (使用这个方法时不能设置:

self.separatorStyle = UITableViewCellSeparatorStyleNone;

-(void)viewDidLayoutSubviews

{

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

        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];

    }

    

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

        [self.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