第一步:
UIView *view = [[UIView alloc]init];
view.layer.mask = [self addCornerWithRoundedRect:tagLabel.bounds TopLeft:7.5 TopRight:7.0 BottomLeft:0.0 BottomRight:7.0];
第二步:
-(CAShapeLayer *)addCornerWithRoundedRect:(CGRect)bounds TopLeft:(CGFloat)topLeft TopRight:(CGFloat)topRight BottomLeft:(CGFloat)bottomLeft BottomRight:(CGFloat)bottomRight
{
CGFloat minX = bounds.origin.x;
CGFloat minY = bounds.origin.y;
CGFloat maxX = bounds.origin.x + bounds.size.width;
CGFloat maxY = bounds.origin.y + bounds.size.height;
//获取四个圆心
CGFloat topLeftCenterX = minX + topLeft;
CGFloat topLeftCenterY = minY + topLeft;
CGFloat topRightCenterX = maxX - topRight;
CGFloat topRightCenterY = minY + topRight;
CGFloat bottomLeftCenterX = minX + bottomLeft;
CGFloat bottomLeftCenterY = maxY - bottomLeft;
CGFloat bottomRightCenterX = maxX - bottomRight;
CGFloat bottomRightCenterY = maxY - bottomRight;
//虽然顺时针参数是YES,在iOS中的UIView中,这里实际是逆时针
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddArc(path, NULL, topLeftCenterX, topLeftCenterY, topLeft, M_PI, M_PI*3/2, false);
CGPathAddArc(path, NULL, topRightCenterX, topRightCenterY, topRight, M_PI*3/2, 0, false);
CGPathAddArc(path, NULL, bottomRightCenterX, bottomRightCenterY, bottomRight, 0, M_PI/2, false);
CGPathAddArc(path, NULL, bottomLeftCenterX, bottomLeftCenterY, bottomLeft, M_PI/2, M_PI, false);
CGPathCloseSubpath(path);
CAShapeLayer *shapLayer = [CAShapeLayer layer];
shapLayer.frame = bounds;
shapLayer.path = path;
return shapLayer;
}