UIView圆角设置

对于UIview的圆角设置最简单的就是layer的两个属性分别是cornerRadius和masksToBounds,但是对于设置其中某一个角为圆角的时候需要使用贝塞尔曲线

UIView *aView = [[UIView alloc] init];

aView.frame = CGRectMake(0, 0, 300, 200);

aView.backgroundColor = [UIColor redColor];

[self.view addSubview:aView];

//设置所需的圆角位置以及大小 UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:aView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];

maskLayer.frame = aView.bounds;

maskLayer.path = maskPath.CGPath;

aView.layer.mask = maskLayer;

其中UIRectCornerBottomLeft 和UIRectCornerBottomRight,是一个枚举,里面还包括左上角和右上角
但是再某些时候这么设置圆角,对于应用的来说会很占用资源,所以就要实现比较麻烦的贝塞尔曲线了。

posted @ 2015-11-20 17:56  _Ace  阅读(400)  评论(0编辑  收藏  举报