Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>A note on your actual question</h2> <p>Paths already do that. Lines, arcs, curves, etc. are all added from the current point. It looks like you are passing the current point for the x and y arguments in <code>CGPathAddArc(...)</code> but those arguments are used for the center of the arc, not the start.</p> <hr> <h1>A much better way of doing a donut chart.</h1> <p>That said, there is a much better way of doing donut charts. First you do the single arc in te center of the donut then you create a new path by stroking that arc. This allows you to customize the width of the donut very easily. I've described this and broken down the code in great detail in <a href="https://stackoverflow.com/a/15868472/608157">this answer</a> but here is a shorter version of the shape itself.</p> <h2>Code to do this</h2> <p>Create the arc in the center of the donut (orange line in the below image)</p> <p><img src="https://i.stack.imgur.com/3RRdU.png" alt="enter image description here"></p> <pre><code>CGMutablePathRef arc = CGPathCreateMutable(); CGPathMoveToPoint(arc, NULL, startPoint.x, startPoint.y); CGPathAddArc(arc, NULL, centerPoint.x, centerPoint.y, radius, startAngle, endAngle, YES); </code></pre> <p>Create a new path by stroking that path (dotted shape in the image above and filled shape in the image below):</p> <p><img src="https://i.stack.imgur.com/9IPag.png" alt="enter image description here"></p> <pre><code>CGFloat lineWidth = 10.0; CGPathRef strokedArc = CGPathCreateCopyByStrokingPath(arc, NULL, lineWidth, kCGLineCapButt, kCGLineJoinMiter, // the default 10); // 10 is default miter limit </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload