在视图中设置角落

时间:2012-03-20 08:14:35

标签: iphone quartz-2d

我知道我可以用Rounded Corner制作UIView

view.layer.cornerRadius = 10;

现在我想知道如何在选定角落制作圆角?就像在左上角和右上角而不是在左下角和右下角。我怎么能这样做?

提前致谢...

2 个答案:

答案 0 :(得分:0)

两种方法:

1. use CALayer mask, mask out the corner you don't want.

2. use Core Graphic, create a clip path.

答案 1 :(得分:0)

这样的东西只会画出顶角 -

- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];

UIBezierPath* roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(44.5, 12.5, 69, 46) byRoundingCorners: UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii: CGSizeMake(10, 10)];
[[UIColor whiteColor] setFill];
[roundedRectanglePath fill];

[[UIColor blackColor] setStroke];
roundedRectanglePath.lineWidth = 0.5;
[roundedRectanglePath stroke];

}