1、设置四个角为同一弧度的圆角
UIView *cornerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 120, 10)];
cornerView.backgroundColor = [UIColor whiteColor];
cornerView.layer.masksToBounds = YES;
cornerView.layer.cornerRadius = 8;
[self addSubview:cornerView];
2、设置某个角为圆角
UIRectCornerTopLeft //上部左角
UIRectCornerTopRight //上部右角
UIRectCornerBottomLeft //下部左角
UIRectCornerBottomRight //下部右角
UIRectCornerAllCorners // 设置所有的角
可以通过 “|” 组合使用
UIView *cornerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 120, 10)];
cornerView.backgroundColor = [UIColor redColor];
[self addSubview:cornerView];
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cornerView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(8, 8)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = cornerView.bounds;
maskLayer.path = maskPath.CGPath;
cornerView.layer.mask = maskLayer;
网友评论