我想在我的UIView中使用圆角样式,下面是我的代码:
UIBezierPath *maskPath1 = [UIBezierPath bezierPathWithRoundedRect:self.styleView1.bounds
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
cornerRadii:CGSizeMake(4, 4)];
CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init];
maskLayer1.frame = self.styleView1.bounds;
maskLayer1.path = maskPath1.CGPath;
self.styleView1.layer.borderWidth = 1;
[self.styleView1.layer setBorderColor:[[UIColor lightGrayColor] CGColor]];
self.styleView1.layer.mask = maskLayer1;其效果如下:

墙角是空白的,就像Photoshop中的羽毛效果一样。
但我想要的是:

怎样才能实现呢?
发布于 2015-01-20 05:10:37
您可以将顶部视图的半径设置为下面的代码检查(how to set cornerRadius for only bottom-left,bottom-right and top-left corner of a UIView?)以供参考。
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:yourView.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadii:CGSizeMake(10.0, 10.0)];
CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
shapeLayer.frame = yourView.bounds;
shapeLayer.path = path.CGPath;
yourView.layer.mask = shapeLayer;你会被跟踪的。

发布于 2015-01-20 04:49:54
如果self是一个UIViewController或UISplitViewController,那么self没有边界,它是一个控制器。
试试这个:
CGRect bounds = self.view.bounds;
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.styleView1.bounds
byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
cornerRadii:CGSizeMake(10.0, 10.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = bounds;
maskLayer.path = maskPath.CGPath;
self.styleView1.layer.mask = maskLayer;https://stackoverflow.com/questions/28037920
复制相似问题