这里使用button作为示例:
众所周知,设置控件的圆角使用layer.cornerRadius属性即可,但是这样设置成的结果是4个边角都是圆角类型。
下面指定设置某个角为圆角
//利用班赛尔曲线画角
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:button.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(10, 10)];
CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
shapeLayer.frame = button.bounds;
shapeLayer.path = bezierPath.CGPath;
button.layer.mask = shapeLayer;
typedef NS_OPTIONS(NSUInteger, UIRectCorner) {
UIRectCornerTopLeft = 1 << 0, //左上
UIRectCornerTopRight = 1 << 1, //右上
UIRectCornerBottomLeft = 1 << 2, //左下
UIRectCornerBottomRight = 1 << 3, //右下
UIRectCornerAllCorners = ~0UL //全角
};