Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 1.35 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. how to get a pie progress bar
  2. - (void)drawRect:(CGRect)rect
  3. {
  4.     CGFloat circleRadius = (self.bounds.size.width / 2) - (self.strokeWidth * 2);
  5.     CGPoint circleCenter = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
  6.     CGRect circleRect = CGRectMake(circleCenter.x - circleRadius, circleCenter.y - circleRadius, 2 * circleRadius, 2 * circleRadius);
  7.  
  8.     CGContextRef context = UIGraphicsGetCurrentContext();
  9.     CGContextSaveGState(context);
  10.  
  11.     // Draw stroked circle to delineate circle shape.
  12.  
  13.     CGContextSetStrokeColorWithColor(context, self.fillColor.CGColor);
  14.     CGContextSetLineWidth(context, self.strokeWidth);
  15.     CGContextAddEllipseInRect(context, circleRect);
  16.     CGContextStrokePath(context);
  17.  
  18.     // Draw filled wedge (clockwise from 12 o'clock) to indicate progress
  19.  
  20.     self.progress = MIN(MAX(0.0, self.progress), 1.0);
  21.  
  22.     CGFloat startAngle = -M_PI_2;
  23.     CGFloat endAngle = startAngle + (progress * 2 * M_PI);
  24.  
  25.     CGContextSetFillColorWithColor(context, self.fillColor.CGColor);
  26.     CGContextMoveToPoint(context, circleCenter.x, circleCenter.x);
  27.     CGContextAddLineToPoint(context, CGRectGetMidX(circleRect), CGRectGetMinY(circleRect));
  28.     CGContextAddArc(context, circleCenter.x, circleCenter.y, circleRadius, startAngle, endAngle, NO);
  29.     CGContextClosePath(context);
  30.     CGContextFillPath(context);
  31.  
  32.     CGContextRestoreGState(context);
  33. }