我們知道設(shè)置UIView的Layer的cornerRadius屬性即可改變View的圓角跺讯。如果要單獨設(shè)置某一個角或者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;