Round some corners of UIView and round the view’s layer’s border too

前端 未结 3 1334
鱼传尺愫
鱼传尺愫 2020-12-25 15:09

I am trying to round the bottom two corners of a UIView, and have the layer’s border show up rounded as well. I am currently doing:

UIRectCorners corners = U         


        
3条回答
  •  不知归路
    2020-12-25 16:08

    Here is the small code. Alloc init a view and send to this method to get corners rounded. You can optionally round any of the corners u want. Also give shadow stroke color.

     -(void) setMaskTo:(UIView*)view byRoundingCorners:(UIRectCorner)corners withColor:  (UIColor*) color
    {
     UIBezierPath* rounded = [UIBezierPath bezierPathWithRoundedRect:view.bounds  byRoundingCorners:corners cornerRadii:CGSizeMake(9.0, 9.0)];
    
    CAShapeLayer* shape = [[[CAShapeLayer alloc] init] autorelease];
    [shape setPath:rounded.CGPath];
    shape.strokeColor = [[UIColor grayColor] CGColor];
    
    view.backgroundColor=color;
    view.layer.mask = shape;
    }
    

    Call the method like this.

    [self setMaskTo:ABCView byRoundingCorners:UIRectCornerAllCorners withColor:[UIColor greenColor]];
    

提交回复
热议问题