I'm trying to draw a circle using UIBezierPath(ovalInRect: CGRectMake())
. Then I'll change the strokeEnd
property. When this happens, either end of the circular line have sharp corners. Is there any way to round out these corners?
(I would like to make the beginning and end of this line curved)
To use them in SwiftUI 2.0 under iOS, you have to create an object called a Shape, a definition that has one required method within it. The code below illustrates a quadratic Bézier curve much like the one you see above. P0 is represented by path.move. P1 is the control point and P2 the to: in the code, aka the final coordinate.
In math-speak, a Bézier curve is defined by a set of control points P0 through P n, where n is called its order ( n = 1 for linear, 2 for quadratic, etc.). The formula used is beyond most mere mortals, I fear, but is beautifully illustrated by this animated GIF.
You may be surprised to learn that Bézier didn’t invent the curves named after him — he just made them famous.
Assuming you are using a CAShapeLayer
to draw this, just set the lineCap
, e.g.:
layer.lineCap = .round
For drawRect based solutions use lineCapStyle
let path = UIBezierPath(...)
path.lineCapStyle = .round
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With