给UIView添加指定角为圆角:
原View长这样:
添加以下代码:
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_animationView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = _animationView.bounds;
maskLayer.path = maskPath.CGPath;
_animationView.layer.mask = maskLayer;
运行:
其中,
byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight
指定了需要成为圆角的角。该参数是UIRectCorner类型的,可选的值有:
* UIRectCornerTopLeft
* UIRectCornerTopRight
* UIRectCornerBottomLeft
* UIRectCornerBottomRight
* UIRectCornerAllCorners
从名字很容易看出来代表的意思,使用“|”来组合就好了。