美文网首页iOS
tableView 取消 cell 默认下划线样式 - iOS

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

作者: survivorsfyh | 来源:发表于2020-11-09 17:06 被阅读0次

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];
}

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

相关文章

网友评论

    本文标题:tableView 取消 cell 默认下划线样式 - iOS

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