我正在尝试仅使表格 View 的右上角和左上角变圆。我正在使用下面的代码,它似乎只是在左上角四舍五入...

CAShapeLayer *topLayer = [CAShapeLayer layer];
UIBezierPath *roundedPath =
[UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerTopLeft cornerRadii:CGSizeMake(9.f, 9.0f)];
topLayer.path = [roundedPath CGPath];

最佳答案

希望这会起作用。
找到顶角路径以创建 mask 层

UIBezierPath *PathToMask;
PathToMask = [UIBezierPath bezierPathWithRoundedRect:self.testView.bounds
                                 byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
                                       cornerRadii:CGSizeMake(8.0, 8.0)];

使用UIBezierPath maskPath创建形状图层蒙版
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame =self.testView.bounds;
maskLayer.path = PathToMask.CGPath;

设置 mask 层maskLayer
self.testView.layer.mask = maskLayer;

10-08 06:19