我使用以下方法在我的应用程序中的视图上获得圆角:
(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的圆角,我如何仅在左上角和右上角应用效果并保持左下角和右下角的平方?
答案 0 :(得分: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)];
答案 1 :(得分: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;