Daphyduck
Daphyduck

Reputation: 127

Custom UIBezierPath in swift (Arc trouble)

I write this code :

let leftUpPath = UIBezierPath()
leftUpPath.move(to: CGPoint(x: 40, y: 40))
leftUpPath.addArc(withCenter: CGPoint(x: 40, y: 40),
    radius: 10,
    startAngle: CGFloat(Double.pi),
    endAngle: CGFloat(3*Double.pi),
    clockwise: true)
leftUpPath.addLine(to: CGPoint(x: 30, y: 50))
leftUpPath.addLine(to: CGPoint(x: 90, y: 50))
leftUpPath.addLine(to: CGPoint(x: 80, y: 30))
leftUpPath.addLine(to: CGPoint(x: 40, y: 30))

and this show me this in my storyboard:

Story Board

but I want this :

what I want

If anyone have the solution, I think my trouble is where I draw the Arc... Thanks for your help

Upvotes: 0

Views: 92

Answers (1)

rmaddy
rmaddy

Reputation: 318774

The first point and the arc were incorrect. You need:

let leftUpPath = UIBezierPath()
leftUpPath.move(to: CGPoint(x: 40, y: 30))
leftUpPath.addArc(withCenter: CGPoint(x: 40, y: 40),
                  radius: 10,
                  startAngle: .pi * 3 / 2,
                  endAngle: .pi,
                  clockwise: false)
leftUpPath.addLine(to: CGPoint(x: 30, y: 50))
leftUpPath.addLine(to: CGPoint(x: 90, y: 50))
leftUpPath.addLine(to: CGPoint(x: 80, y: 30))
leftUpPath.addLine(to: CGPoint(x: 40, y: 30))

Upvotes: 1

Related Questions