在一个多cell的Tab了View 中设置第一个和最后一个cell的圆角
其实还是贝塞尔去画 给cell 加一个view
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0 && indexPath.section == 0) {
UIView *backView = [[UIView alloc] initWithFrame:cell.bounds];
backView.backgroundColor = [UIColor whiteColor];
backView.layer.cornerRadius = 15;
cell.backgroundView = backView;
} else if ((indexPath.section == 1 && indexPath.row == 0) || (indexPath.section == 2 && indexPath.row == 0)) {
UIView *backView = [[UIView alloc] initWithFrame:cell.bounds];
backView.backgroundColor = [UIColor whiteColor];
UIRectCorner corner = UIRectCornerTopLeft | UIRectCornerTopRight;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:backView.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(15, 15)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = backView.bounds;
maskLayer.path = path.CGPath;
backView.layer.masksToBounds = YES;
backView.layer.mask = maskLayer;
cell.backgroundView = backView;
} else if ((indexPath.section == 1 && indexPath.row == 2) || (indexPath.section == 2 && indexPath.row == 4)) {
UIView *backView = [[UIView alloc] initWithFrame:cell.bounds];
backView.backgroundColor = [UIColor whiteColor];
UIRectCorner corner = UIRectCornerBottomLeft | UIRectCornerBottomRight;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:backView.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(15, 15)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = backView.bounds;
maskLayer.path = path.CGPath;
backView.layer.masksToBounds = YES;
backView.layer.mask = maskLayer;
cell.backgroundView = backView;
}
}
标签:indexPath,tableViewCell,自定义,圆角,bounds,cell,backView,maskLayer,UIView From: https://www.cnblogs.com/xiaodeng90/p/17340123.html