iOS 초보

PieChart

돌비 2014. 7. 2. 18:38
- (void)drawRect:(CGRect)rect
{
  float sum = m_Val1 + m_Val2;
  float mult = (360/sum);
  
  float startDeg = 0;
  float endDeg = 0;
  int x = 100;
  int y = 100;
  int r = 60;
  
  
  //
  CGContextRef ctx = UIGraphicsGetCurrentContext();
  CGContextSetRGBStrokeColor(ctx, 1.0, 1.0, 1.0, 1.0);
  CGContextSetLineWidth(ctx, 2.0);
  
  startDeg = 0;
  endDeg = m_Val1 * mult;
  
  if(startDeg != endDeg)
  {
    CGContextSetRGBFillColor(ctx, 1.0, 0.0, 0.0, 1.0);
    CGContextMoveToPoint(ctx, x, y);
    CGContextAddArc(ctx, x, y, r, startDeg*M_PI/180.0, endDeg*M_PI/180.0, 0);
    CGContextClosePath(ctx);
    CGContextFillPath(ctx);
  }
  
  
  //
  startDeg = endDeg;
  endDeg = endDeg + (m_Val2 * mult);
  
  if(startDeg != endDeg)
  {
    CGContextSetRGBFillColor(ctx, 0.0, 1.0, 0.0, 1.0);
    CGContextMoveToPoint(ctx, x, y);
    CGContextAddArc(ctx, x, y, r, startDeg*M_PI/180.0, endDeg*M_PI/180.0, 0);
    CGContextClosePath(ctx);
    CGContextFillPath(ctx);
  }
  
}


반응형