tableView 取消 cell 默认下划线样式 - iOS

tableView 无数据的情况下会配置一个默认暂无数据的样式,但 tableView 实例化后会渲染出很多行 cell 的线条,此时看着很不美观,配置如下 code 即可消除 cell 的下横线,需要实例化的时候对 tableView 的数据源进行判空,若有数据的情况下想要保留该下划线则需要不将该属性设置为 none。

if (kArrayIsEmpty(dataSource)) {
    tabView.backgroundColor = [UIColor clearColor];
    tabView.separatorStyle = UITableViewCellSeparatorStyleNone; // 取消默认 cell 下划线样式
    UIView *bgView = [[UIView alloc] init];
    bgView.frame = tabView.bounds;
    UIImageView *bgImgView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"imgNoData"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    NSUInteger bgViewWidth = CGRectGetWidth(bgView.frame);
    NSUInteger bgViewHeight = CGRectGetHeight(bgView.frame);
    NSUInteger bgImgHeight = (bgViewWidth / 6) * 4 / 2;
    bgImgView.frame = CGRectMake(bgViewWidth / 6, bgViewHeight / 2 - bgImgHeight / 2, (bgViewWidth / 6) * 4, bgImgHeight);
    [bgView addSubview:bgImgView];
    tabView.backgroundView = bgView;
} else {
    tabView.backgroundColor = [UIColor generateDynamicColor:[UIColor whiteColor] darkColor:[UIColor blackColor]];
    tabView.delegate = self;
    tabView.dataSource = self;
    [tabView registerClass:[InvoiceCell class] forCellReuseIdentifier:CellIdentifierInvoiceRecordsList];
}

以上便是此次分享的全部内容,希望能对大家有所帮助!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容