美文网首页
3.tableViewCell设置分割线

3.tableViewCell设置分割线

作者: 枫之叶_小乙哥 | 来源:发表于2018-12-10 15:49 被阅读4次

1.给tableview设置背景颜色


 self.tableView.backgroundColor = ZGKColor(239, 239, 244, 1);

2.在自定义cell中重写setFrame方法(设置cell之间的间隔为10)


- (void)setFrame:(CGRect)frame {
    
    CGFloat margin = 10;
    
    frame.origin.y += margin;
    frame.size.height -= margin;
 
    [super setFrame:frame];
    
}

3.重新调整cell的高度,注意cell的高度要加上分割线或者间距

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {   // 设置分割线的cell
        return 180;
    }else{ 
        return 60;
    }
    return 60;
    
}

-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

调试以后发现, cell的高度在代理方法中设置为180,经过重写setFrame方法后吗, cell的高度调整为170,留出10的高度就成了cell之间的间隙咯。


Snip20181210_1.png

相关文章

网友评论

      本文标题:3.tableViewCell设置分割线

      本文链接:https://www.haomeiwen.com/subject/zetdhqtx.html