//以一个UIView为例
UIView *view = [[UIView alloc] init];
view.frame = CGRectMake(100, 100, 100, 100);
view.backgroundColor = [UIColor purpleColor];
[self.view addSubview:view];
1.这种情况是4个角全部设置
view.layer.cornerRadius = 10;
view.layer.masksToBounds = YES;
2.这种情况是选择哪几个角进行设置
//设置哪几个圆角主要取决于byRoundingCorners的设置
//UIRectCornerTopLeft 左上
//UIRectCornerTopRight 右上
//UIRectCornerBottomLeft 左下
//UIRectCornerBottomRight 右下
//UIRectCornerAllCorners 所有
//组合使用各个值之间用“|”连接,前四个值全设置相当于只设置UIRectCornerAllCorners的效果
//cornerRadii的设置取决于size中的width值
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight | UIRectCornerBottomLeft cornerRadii:CGSizeMake(10, 0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = view.bounds;
maskLayer.path = maskPath.CGPath;
view.layer.mask = maskLayer;