0

I am having an issue with the arc drawing of a UIBezierPath on IOS.

Whilst I get the semblance of an arc, as can be seen from the image, the top, and two sides have flat edges.

The code I am using looks like this:

    let path2 = UIBezierPath()
    path2.addArc(withCenter: arcCentre, radius: radius, startAngle: arcStart, endAngle: arcEnd, clockwise: false)
    path2.addLine(to: finalPoint)
    path2.close()
    color.set()
    path2.fill()

The produced arc is shown in black on the image below.

enter image description here

Any clues as to why this is so, and how to get a perfectly rounded image?

sweetfa
  • 5,457
  • 2
  • 48
  • 62
  • How are you drawing the path? Is it part of a view, or are you adding it as a layer? I suspect your path is getting clipped. – vacawama Jul 29 '20 at 01:45
  • as a stroke() on the path from within override func draw(_ rect: CGRect) – sweetfa Jul 29 '20 at 02:42
  • I think you're just hitting the edges of the view. Make the view larger. – vacawama Jul 29 '20 at 02:45
  • I don't know that line caps are by default rounded. You can try setting the end caps to rounded as in this question: https://stackoverflow.com/questions/34373781/rounding-the-edges-of-a-stroke-in-bezier-path-circle-in-swift – Durstann Jul 29 '20 at 02:55
  • @vacawama you are correct about hitting the view edges. reducing the radius of the arc confirms this. – sweetfa Jul 29 '20 at 03:30
  • you can also set view.clipsToBounds = false or setting view.layer.frame larger i think, as draw(_ rect:) renders into the views layer. – Ol Sen Jul 29 '20 at 03:44

0 Answers0