//可以去掉分割线
- (void)addSubview:(UIView *)view{
if ([view isKindOfClass:NSClassFromString(@"_UITableViewCellSeparatorView")]) {
return;
}
[super addSubview:view];
}
//改变cell的frame
- (void)setFrame:(CGRect)frame{
/*
左右距离 10 ,y+10,高度减少15
*/
if (frame.size.height < 1) {//直接==0 在Xcode11下编译有bug
[super setFrame:frame];
return;
}
frame.origin.x = 15;
frame.size.width -= 2 * frame.origin.x;
// frame.origin.y += 10;
frame.size.height -= 20;
[super setFrame:frame];
}
//取消点击效果
[tableView deselectRowAtIndexPath:indexPath animated:YES];
//简单修改UITableViewHeaderFooterView的字体、颜色等
//新建个类继承UITableViewHeaderFooterView,然后在layoutSubviews里修改
- (void)layoutSubviews {
[super layoutSubviews];
self.textLabel.font = [UIFont boldSystemFontOfSize:18];
if (@available(iOS 13.0, *)) {
self.textLabel.textColor = [UIColor labelColor];
} else {
self.textLabel.textColor = [UIColor blackColor];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
cell.preservesSuperviewLayoutMargins = NO;///>=iOS 8,子view和父view间有8个像素
cell.layoutMargins = UIEdgeInsetsMake(0, 20, 0, 20);///>=iOS 8
cell.separatorInset = UIEdgeInsetsMake(0, 20, 0, 20);///<=iOS 7,默认距左15
return cell;
}