我们知道设置UIView的Layer的cornerRadius属性即可改变View的圆角。如果要单独设置某一个角或者2个,3个为圆角,就可以用下面方法。
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(120, 100, 100, 100)];
view.backgroundColor = [UIColor blueColor];
[self.view addSubview:view];
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(15, 15)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = view.bounds;
maskLayer.path = maskPath.CGPath;
view.layer.mask = maskLayer;
网友评论