平常view的圆角可以通过以下设置,4个角都生效
view.layer.cornerRadius = 20;
view.layer.masksToBounds = YES;
如果需要指定一个角为圆角
- byRoundingCorners 指定某个角为圆弧角
有如下参数
typedef NS_OPTIONS(NSUInteger, UIRectCorner) {
UIRectCornerTopLeft = 1 << 0,
UIRectCornerTopRight = 1 << 1,
UIRectCornerBottomLeft = 1 << 2,
UIRectCornerBottomRight = 1 << 3,
UIRectCornerAllCorners = ~0UL
}; - cornerRadii : 为圆角的半径
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 100, 30) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft cornerRadii:CGSizeMake(15, 15)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = CGRectMake(0, 0, 100, 30);
maskLayer.path = maskPath.CGPath;
button.layer.mask = maskLayer;
如图。指定左边上下2个角为圆形