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

前端 未结 10 1189
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:11

    I know it's very late, but i just create one method where you can pass only one or multiple UIRectCorners.

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

提交回复
热议问题