iOS开发tableView分割线顶格,以及隐藏多余的单元格

在iOS开发中,因为各种设计需求,设计师给的标注是cell的分割线顶格的,还有在一个tableView中可能只有1个单元格或者几个单元格,如果不做任何处理,屏幕上就会有没有任何内容的单元格,我们如何隐藏这些多余的cell的分割线呢?直接看代码吧!

//在创建talbleView的下方添加这两个if
    if ([myTableView respondsToSelector:@selector(setSeparatorInset:)]) {
        myTableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    }
    if ([myTableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [myTableView setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
    }

//实现tableview的代理方法
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
}

//隐藏表视图多余单元格的分割线,此方法在创建talbeview的后面调用
- (void)setExtraCellLineHidden: (UITableView *)tableView

{
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值