Drawing a smooth arc with Paths in SwiftUI

672 Views Asked by At

I am trying to create a arc shape with smooth edges as seen in the picture below, however I am having trouble with smoothing out the ends of the arc. I've tried using a Quad Curve but it still doesn't look right. See the code for what I have so far. The code isn't final, and just for testing purposes. Any help would be appreciated. Curved arc

struct SmoothArcExample: View {
var body: some View {
    Path { path in
        let midX = UIScreen.main.bounds.midX
        let base1 = CGPoint(x: midX - 10, y: .zero)
        let base2 = CGPoint(x: midX + 30, y: .zero)
        let ctrl1 = CGPoint(x: midX, y: .zero)
        let ctrl2 = CGPoint(x: midX+20, y: .zero)
        let curv = CGPoint(x: midX, y: 10)
        let peak = CGPoint(x: midX+10, y: 10)
        
        path.move(to: base1)
        path.addQuadCurve(to: curv, control: ctrl1)
        path.addArc(center: peak, radius: 10, startAngle: .degrees(180), endAngle: .degrees(0), clockwise: true)
        path.addQuadCurve(to: base2, control: ctrl2)
    }
    .stroke()
}

}

0

There are 0 best solutions below