5

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

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

1 回答 1

2

希望这会奏效。找到顶角路径以创建遮罩层

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;

设置遮罩层maskLayer

self.testView.layer.mask = maskLayer;
于 2015-02-05T05:35:08.310 回答