圆角
问题描述:
我用下面的方法来得到我的应用程序视图圆角:圆角
(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,我怎么只适用效果在左上角和右上角,并将左下角和右下角平方?
答
尝试创建路径手动
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;
答
我有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)];
看到这个[问题](http://*.com/questions/2264083/rounded-uiview-using-calayers-only-some-corners-how) - 基本上您需要遮罩视图的图层,并且您可以创建一个贝塞尔路径来定义只有一些边角圆整的蒙版 – wattson12 2012-07-23 13:23:57
您应该为视图使用唯一的蒙版以达到此效果。 – holex 2012-07-23 13:49:31