tableView 取消 cell 默认下划线样式 - iOS
2020-11-09 本文已影响0人
survivorsfyh
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];
}
以上便是此次分享的全部内容,希望能对大家有所帮助!