Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get a pie progress bar

I like the small pie progress bar like it's in Xcode, when search for a string in the project (Shift-Command-F), see picture.

How can this be called on iOS? I'd love to have it for a download queue.

Thanks in advance.

Screenshot of Xcode searching for a string in a projekt

like image 618
brainray Avatar asked Dec 06 '22 16:12

brainray


1 Answers

There's no stock circular deterministic progress view. Here's an example drawRect: you might use to implement such a thing.

- (void)drawRect:(CGRect)rect
{
    CGFloat circleRadius = (self.bounds.size.width / 2) - (self.strokeWidth * 2);
    CGPoint circleCenter = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
    CGRect circleRect = CGRectMake(circleCenter.x - circleRadius, circleCenter.y - circleRadius, 2 * circleRadius, 2 * circleRadius);

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSaveGState(context);

    // Draw stroked circle to delineate circle shape.

    CGContextSetStrokeColorWithColor(context, self.fillColor.CGColor);
    CGContextSetLineWidth(context, self.strokeWidth);
    CGContextAddEllipseInRect(context, circleRect);
    CGContextStrokePath(context);

    // Draw filled wedge (clockwise from 12 o'clock) to indicate progress

    self.progress = MIN(MAX(0.0, self.progress), 1.0);

    CGFloat startAngle = -M_PI_2;
    CGFloat endAngle = startAngle + (progress * 2 * M_PI);

    CGContextSetFillColorWithColor(context, self.fillColor.CGColor);
    CGContextMoveToPoint(context, circleCenter.x, circleCenter.x);
    CGContextAddLineToPoint(context, CGRectGetMidX(circleRect), CGRectGetMinY(circleRect));
    CGContextAddArc(context, circleCenter.x, circleCenter.y, circleRadius, startAngle, endAngle, NO);
    CGContextClosePath(context);
    CGContextFillPath(context);

    CGContextRestoreGState(context);
}

You would need to create strokeWidth and fillColor properties to use this code directly, but it should be a start. Here's a sample project with a couple of examples.

like image 66
warrenm Avatar answered Dec 20 '22 16:12

warrenm