- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
? ?
? ? // Cell 分區(qū)圓角
? ? 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;
? ? ? ? }
? ? }
}