JAHelia
JAHelia

Reputation: 7902

Drawing a line with half a circle using UIBezierPath

I'm using this piece of code to draw a straight line using UIBezierPath class as follows:

let myPath = UIBezierPath()
    myPath.move(to: CGPoint(x:10, y:5))
    myPath.addLine(to: CGPoint(x:100, y:5))

    myPath.close()
    UIColor.blue.set()
    myPath.stroke()
    myPath.fill()

however, I don't know how to change this basic drawing to include half a circle in the path to be as follows:

enter image description here

Upvotes: 2

Views: 3439

Answers (1)

Tristan Burnside
Tristan Burnside

Reputation: 2566

From: addArc documentation

myPath.addArc(withCenter: CGPoint(x: 55, y: 5), 
              radius: 10, 
              startAngle: 0, 
              endAngle: CGFloat.pi, 
              clockwise: false)

This should give you about the circle you want. You will also need to break your line into 2 segments.

Upvotes: 3

Related Questions