【发布时间】:2016-11-21 05:20:12
【问题描述】:
是否可以在不将 Bezier 路径掩码应用于最后一个单元格的情况下拥有一个带有圆角部分的 tableview?贝塞尔路径的问题在于它还掩盖了 UITableViewRowActions,并使删除和编辑按钮不可见,但可以正常工作。有什么想法吗?
谢谢。
【问题讨论】:
-
分享您想要实现的图像。
标签: swift xcode uitableview uibezierpath
是否可以在不将 Bezier 路径掩码应用于最后一个单元格的情况下拥有一个带有圆角部分的 tableview?贝塞尔路径的问题在于它还掩盖了 UITableViewRowActions,并使删除和编辑按钮不可见,但可以正常工作。有什么想法吗?
谢谢。
【问题讨论】:
标签: swift xcode uitableview uibezierpath
您只需修改第一个和最后一个单元格的角以产生圆形部分的效果。
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger rowsCount = [self tableView:tableView numberOfRowsInSection:indexPath.section];
if (1 == rowsCount) {
cell.contentView.layer.cornerRadius = 8.f;
cell.contentView.layer.masksToBounds = YES;
} else {
if (0 == indexPath.row) {
CGRect cellRect = cell.contentView.bounds;
CGMutablePathRef firstRowPath = CGPathCreateMutable();
CGPathMoveToPoint(firstRowPath, NULL, CGRectGetMinX(cellRect), CGRectGetMaxY(cellRect));
CGPathAddLineToPoint(firstRowPath, NULL, CGRectGetMinX(cellRect), 8.f);
CGPathAddArcToPoint(firstRowPath, NULL, CGRectGetMinX(cellRect), CGRectGetMinY(cellRect), 8.f, CGRectGetMinY(cellRect), 8.f);
CGPathAddLineToPoint(firstRowPath, NULL, CGRectGetMaxX(cellRect) - 8.f, 0.f);
CGPathAddArcToPoint(firstRowPath, NULL, CGRectGetMaxX(cellRect), CGRectGetMinY(cellRect), CGRectGetMaxX(cellRect), 8.f, 8.f);
CGPathAddLineToPoint(firstRowPath, NULL, CGRectGetMaxX(cellRect), CGRectGetMaxY(cellRect));
CGPathCloseSubpath(firstRowPath);
CAShapeLayer *newSharpLayer = [[CAShapeLayer alloc] init];
newSharpLayer.path = firstRowPath;
newSharpLayer.fillColor = [[UIColor whiteColor] colorWithAlphaComponent:1.f].CGColor;
CFRelease(firstRowPath);
cell.contentView.layer.mask = newSharpLayer;
} else if (indexPath.row == (rowsCount - 1)) {
CGRect cellRect = cell.contentView.bounds;
CGMutablePathRef lastRowPath = CGPathCreateMutable();
CGPathMoveToPoint(lastRowPath, NULL, CGRectGetMinX(cellRect), CGRectGetMinY(cellRect));
CGPathAddLineToPoint(lastRowPath, NULL, CGRectGetMaxX(cellRect), CGRectGetMinY(cellRect));
CGPathAddLineToPoint(lastRowPath, NULL, CGRectGetMaxX(cellRect), CGRectGetMaxY(cellRect) - 8.f);
CGPathAddArcToPoint(lastRowPath, NULL, CGRectGetMaxX(cellRect), CGRectGetMaxY(cellRect), CGRectGetMaxX(cellRect)- 8.f, CGRectGetMaxY(cellRect), 8.f);
CGPathAddLineToPoint(lastRowPath, NULL, 8.f, CGRectGetMaxY(cellRect));
CGPathAddArcToPoint(lastRowPath, NULL, CGRectGetMinX(cellRect), CGRectGetMaxY(cellRect), CGRectGetMinX(cellRect), CGRectGetMaxY(cellRect) - 8.f, 8.f);
CGPathCloseSubpath(lastRowPath);
CAShapeLayer *newSharpLayer = [[CAShapeLayer alloc] init];
newSharpLayer.path = lastRowPath;
newSharpLayer.fillColor = [[UIColor whiteColor] colorWithAlphaComponent:1.f].CGColor;
CFRelease(lastRowPath);
cell.contentView.layer.mask = newSharpLayer;
}
}
}
【讨论】: