Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You basically just need to construct a path that defines the area to be filled (e.g. using <code>CGPathAddArc</code>), clip the graphics context to that path using <code>CGContextClip</code> and then just draw your image.</p> <p>Here's an example of a <code>drawRect:</code> method you could use in a custom view:</p> <pre><code>- (void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGFloat progress = 0.7f; //This would be a property of your view CGFloat innerRadiusRatio = 0.5f; //Adjust as needed //Construct the path: CGMutablePathRef path = CGPathCreateMutable(); CGFloat startAngle = -M_PI_2; CGFloat endAngle = -M_PI_2 + MIN(1.0f, progress) * M_PI * 2; CGFloat outerRadius = CGRectGetWidth(self.bounds) * 0.5f - 1.0f; CGFloat innerRadius = outerRadius * innerRadiusRatio; CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); CGPathAddArc(path, NULL, center.x, center.y, innerRadius, startAngle, endAngle, false); CGPathAddArc(path, NULL, center.x, center.y, outerRadius, endAngle, startAngle, true); CGPathCloseSubpath(path); CGContextAddPath(ctx, path); CGPathRelease(path); //Draw the image, clipped to the path: CGContextSaveGState(ctx); CGContextClip(ctx); CGContextDrawImage(ctx, self.bounds, [[UIImage imageNamed:@"RadialProgressFill"] CGImage]); CGContextRestoreGState(ctx); } </code></pre> <p>To keep it simple, I've hard-coded a few things – you obviously need to add a property for <code>progress</code> and call <code>setNeedsDisplay</code> in the setter. This also assumes that you have an image named <code>RadialProgressFill</code> in your project.</p> <p>Here's an example of what that would roughly look like:</p> <p><img src="https://i.stack.imgur.com/JlEBF.png" alt="Screenshot"></p> <p>I hope you have a better-looking background image. ;)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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