如何在UITableView上只转角?

Luk*_*uke 5 rounded-corners uitableview ios uibezierpath

我试图只围绕我的桌面视图的右上角和左上角.我正在使用下面的代码,它似乎只是绕过左上角......

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

nee*_*jPK 2

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

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

使用 UIBezierPath maskPath 创建形状图层蒙版

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; 
maskLayer.frame =self.testView.bounds;
maskLayer.path = PathToMask.CGPath;
Run Code Online (Sandbox Code Playgroud)

设置遮罩层maskLayer

self.testView.layer.mask = maskLayer;
Run Code Online (Sandbox Code Playgroud)