- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
// Cell 分区圆角
CGFloat radius = 10;
if ([tableView numberOfRowsInSection:indexPath.section] == 1) {
// 当前section有且仅有1行,则四个角都要绘制圆角
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.bounds cornerRadius:radius];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = cell.bounds;
maskLayer.path = maskPath.CGPath;
cell.layer.mask = maskLayer;
} else {
// 当前section不止1行
if (indexPath.row == 0) {
// 当前cell为第一行
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.bounds
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = cell.bounds;
maskLayer.path = maskPath.CGPath;
cell.layer.mask = maskLayer;
} else if (indexPath.row == [tableView numberOfRowsInSection] - 1) {
// 当前cell为最后一行
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.bounds
byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight
cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = cell.bounds;
maskLayer.path = maskPath.CGPath;
cell.layer.mask = maskLayer;
} else {
// 当前cell为中间行
cell.layer.mask = nil;
}
}
}
记录:tableview之sectiin圆角
最新推荐文章于 2024-08-15 23:13:26 发布