iOS UITableView 分割线从零开始

第一种(不自己画线):

代码如下

// tableView的分割线从零开始
-(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];
    }
}

第二种

自定义Cell 在Cell中自己画线

要使用这种方法 把tableView的自带分割线先去掉

self.table.separatorStyle = UITableViewCellSeparatorStyleNone;

然后在自定义cell里面

写一个view在最底部 当作分割线 就好了。

原文地址:https://www.cnblogs.com/huanying2000/p/6192490.html