【发布时间】:2016-04-05 10:22:44
【问题描述】:
我想用这样的值来完善我的 UIViewtop-left-radius:20; bottom-right-radius:5; bottom-left-radius:5; 和 top-right-radius:10;
//For rounder `UIRectCornerBottomLeft & UIRectCornerBottomRight` I use
UIBezierPath *maskPath0 = [UIBezierPath bezierPathWithRoundedRect:self.messageView.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(5.0, 5.0)];
CAShapeLayer *maskLayer0 = [[CAShapeLayer alloc] init];
maskLayer0.frame = self.bounds;
maskLayer0.path = maskPath0.CGPath;
self.messageView.layer.mask = maskLayer0;
//For rounder `TopRight` I use
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.messageView.bounds byRoundingCorners:(UIRectCornerTopRight) cornerRadii:CGSizeMake(10.0, 10.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.messageView.layer.mask = maskLayer;
//For rounder `TopLeft` I use
UIBezierPath *maskPath2 = [UIBezierPath bezierPathWithRoundedRect:self.messageView.bounds byRoundingCorners:(UIRectCornerTopLeft) cornerRadii:CGSizeMake(20.0, 20.0)];
CAShapeLayer *maskLayer2 = [[CAShapeLayer alloc] init];
maskLayer2.frame = self.bounds;
maskLayer2.path = maskPath2.CGPath;
self.messageView.layer.mask = maskLayer2;
但我得到的结果是角半径为TopLeft 的视图,值为 20。
我怎样才能做到这一点?任何帮助将不胜感激。
【问题讨论】:
-
您需要使用同一个对象添加所有圆角半径,到目前为止,您的最后一个对象正在应用圆角半径。
-
@VatsalK 你是对的,但现在我不知道将它添加到同一个对象中,你能在代码中更多地描述它。非常感谢
-
这种情况下,你需要根据自己的需要来绘制形状,你可以参考这个link或者你可以制作相同形状的图像并将图像设置为背景。
-
在这个较老的问题上,值得注意的是最新的答案 - 我给它发了一个赏金 - 是完美的,只需将其粘贴进去,不要做任何其他事情。
标签: ios layer uibezierpath