iOS开发中tableView的分割线的处理问题

在iOS开发中,为使tableView的分割线达到预期效果,通常需要进行一些自定义处理。包括隐藏多余分割线、设置分割线样式、颜色以及实现全屏覆盖。本文介绍了如何通过设置tableFooterView实现分割线透明,调整separatorColor和separatorStyle,以及在willDisplayCell方法中删除或重绘特定行的分割线。

有时候,我们在使用tableview 的时候会发现,想要的效果,可能不是原生的,tableView 的原生的分割线并不是完成的填充在两边的,而有时候我们需要的就是完全的分割线,这时候我们就需要处理一些事情
一:隐藏多余的分割线,
[self setExtraCellLineHidden:tableView];
- (void)setExtraCellLineHidden: (UITableView *)tableView
{
UIView *view = [UIView new];
view.backgroundColor = [UIColor clearColor];
[tableView setTableFooterView:view];
}
这其实就相当于把分割线给设置成透明的
二:设置分割线的样式,粗细,以及分割线的颜色
[_tableView setSeparatorColor:[UIColor redColor]];
[_tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
同时,分割线的种类也是一个枚举值,通常来说一般是具有以下三种样式
typedef NS_ENUM(NSInteger, UITableViewCellSeparatorStyle) {
UITableViewCellSeparatorStyleNone, //没有分割线
UITableViewCellSeparatorStyleSingleLine, // 细线的分割线
UITableViewCellSeparatorStyleSingleLineEtched // This separator style is only supported for grouped style table views currently // 被腐蚀的分割线,目前只是支持分组样式的tableView
} __TVOS_PROHIBITED;

三:设置分割线,整个屏幕两端,并且设置颜色,或是删除特定的某一行的分割线
在重绘方法中重新设置tableView的分割线的

  • (void)tableView:(UITableView )tableView willDisplayCell:(UITableViewCell )cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    //重设cell线的颜色
    [_bodyTable setSeparatorColor:getG4Corlor];
    //tableviewcell分割线画至最左边
    if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
    [tableView setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
    [tableView setLayoutMargins:UIEdgeInsetsZero];
    }

    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
    [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    // 这就是删除某一行的的分割线
    if (indexPath. section == 0 && indexPath. row == 1 ) {

[cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 10000000)];

}
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值