Objective-c 设置View每一个角的圆角值

第一步:

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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值