iOS开发之指定UIView的某几个角为圆角

使用UIBezierPath。下面给出一段示例代码。

 1 UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(120, 10, 80, 80)];
 2 view2.backgroundColor = [UIColor redColor];
 3 [self.view addSubview:view2];
 4 
 5 UIBezierPath maskPath = [UIBezierPath bezierPathWithRoundedRect:view2.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
 6 CAShapeLayer maskLayer = [[CAShapeLayer alloc] init];
 7 maskLayer.frame = view2.bounds;
 8 maskLayer.path = maskPath.CGPath;
 9 view2.layer.mask = maskLayer;
10 
11 
12 //指定了需要成为圆角的角。该参数是UIRectCorner类型的,可选的值有:
13 
14 * UIRectCornerTopLeft
15 * UIRectCornerTopRight
16 * UIRectCornerBottomLeft
17 * UIRectCornerBottomRight
18 * UIRectCornerAllCorners

 

posted @ 2016-04-25 13:49  optt  阅读(843)  评论(0编辑  收藏  举报