2

我使用以下方法在我的应用程序中的视图上获得圆角:

(objective-c:)
hoursTable.layer.cornerRadius = 5.0;
[hoursTable setClipsToBounds:YES];

(my actual code is in rubymotion:)
self.view.layer.cornerRadius = 10
self.view.layer.masksToBounds = true

现在该视图的所有角都以 10pt 为圆角,我如何仅将效果应用于左上角和右上角,而使左下角和右下角保持正方形?

4

2 回答 2

3

我在 UIView 上有这个代码的类别:

- (void)setRoundedCorners:(UIRectCorner)corners radius:(CGSize)size {
UIBezierPath* maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:size];

CAShapeLayer* maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;

self.layer.mask = maskLayer;
[maskLayer release];
}

如果您使用 ARC,请删除最后一行。

使用示例:

[hoursTable setRoundedCorners:UIRectCornerTopLeft|UIRectCornerTopRight radius:CGSizeMake(5.0, 5.0)];
于 2012-07-23T13:27:41.563 回答
0

尝试手动创建路径

CAShapeLayer* shape = [CAShapeLayer layer];
CGMutablePathRef path = CGPathCreateMutable();
/*...*/
CGPathMoveToPoint(path, NULL, 0, 0);
/*create path for view*/

shape.path = path;
CGPathRelease(path);
view.layer.mask = shape;
于 2012-07-23T13:25:43.170 回答