how to set cornerRadius for only bottom-left,bottom-right and top-left corner of a UIView?

前端 未结 10 1193
Happy的楠姐
Happy的楠姐 2020-12-04 06:49

Is there a way to set cornerRadius for only bottom-left,bottom-right and top-left corner of a UIView?

I tried the following, but it ended up making the view disappea

10条回答
  •  时光说笑
    2020-12-04 07:12

    Try this code

    -(void)setMaskTo:(UIView*)view byRoundingCorners:(UIRectCorner)corners {
        UIBezierPath* rounded = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(10.0, 10.0)];
        CAShapeLayer* shape = [[CAShapeLayer alloc] init];
        [shape setPath:rounded.CGPath];
        view.layer.mask = shape;
    }
    

    call using

    [self setMaskTo:myView byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight];
    

    Available options:

    UIRectCornerTopLeft, UIRectCornerTopRight,UIRectCornerBottomLeft,UIRectCornerBottomRight,UIRectCornerAllCorners
    

提交回复
热议问题