UIBezierPath Triangle with rounded edges

前端 未结 6 1434
耶瑟儿~
耶瑟儿~ 2020-11-30 18:00

I have designed this code to generate a Bezier Path that is used as a path for a CAShapeLayer to mask a UIView (the view\'s height and width are variable)

This code

6条回答
  •  天命终不由人
    2020-11-30 18:30

    Is much much more less complicated would be just adding two lines of code:

    UIBezierPath *bezierPath = [UIBezierPath bezierPath];
    bezierPath.lineCapStyle = kCGLineCapRound;
    bezierPath.lineJoinStyle = kCGLineJoinRound;
    
    CGPoint center = CGPointMake(rect.size.width / 2, 0);
    ... 
    

    EDIT:

    To see that corners are rounded you need to make triangle a little less than rect bounds:

        CGPoint center = CGPointMake(rect.size.width / 2, 10);
        CGPoint bottomLeft = CGPointMake(10, rect.size.height - 10);
        CGPoint bottomRight = CGPointMake(rect.size.width - 10, rect.size.height - 10);
    

提交回复
热议问题