UIBezierPath - add a rounded corner

I use UIBezierPath to draw a curve. However, the curve works, I can not curve the borders of the line.

enter image description here

If you look at the upper / lower end of the curve, you will see that the edges are flattened out, this is not what I want. Is there a way to curve edges?

I use a simple UIBezierPath to draw a (almost) half circle. This creates the shape of the curve that I want:

 CAShapeLayer *circle = [CAShapeLayer layer]; circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(0, 0) radius:70 startAngle:1.0472 endAngle:5.23599 clockwise:NO].CGPath; circle.fillColor = [UIColor clearColor].CGColor; circle.strokeColor = [UIColor colorWithWhite:1.0 alpha:0.2].CGColor; circle.lineWidth = 18.0; circle.cornerRadius = 10.0; circle.position = CGPointMake(100, 100); circle.anchorPoint = CGPointMake(0.5, 0.5); [mainView.layer addSublayer:circle]; 

Despite setting the cornerRadius property, the corners are not bent. What am I doing wrong?

Thanks for your time, Dan.

+5
source share
2 answers

Include the following.

 circle.lineCap = kCALineJoinRound; 

For Swift 3.0

 circle.lineCapStyle = .Round; 
+7
source

Swift 4.0

 circle.lineCap = kCALineCapRound 

and if you want your line intersections to be rounded as well, set

 circle.lineJoin = kCALineCapRound 

.

+1
source

Source: https://habr.com/ru/post/1264197/


All Articles