iOS draw pie charts

// Get the context
    CGContextRef UIGraphicsGetCurrentContext CTX = ();
    
    // path of joining
    a CGPoint Center = CGPointMake (125, 125);
    CGFloat RADIUS = 100;
    
    // first sector
    // start angle
    CGFloat startA = 0;
    // the sector accounting point of view, there can not be divided by 100 note, two integers or integer division, the result is zero, how there will have decimals, the 100 is not changed to 100.0 automatically promoted to type float ah. Their proportion angle = 360 [deg.] *
    CGFloat angle = 25/2 * 100.0 * M_PI;
    CGFloat endA + = startA angle;
    // path segment
    UIBezierPath * path = [UIBezierPath bezierPathWithArcCenter: center radius: radius startAngle: startA endAngle: endA clockwise : YES];
    [addLineToPoint path: Center];
    
    [[UIColor redColor] SET];
    // add the path to the context
    CGContextAddPath (ctx, path.CGPath);
    // Render context to view
    CGContextFillPath (CTX);
    
    // second sector
    startA = endA;
    angle = 50/2 * 100.0 * M_PI;
    endA + = startA angle;
    UIBezierPath path1 * = [UIBezierPath bezierPathWithArcCenter: Center RADIUS: RADIUS startAngle: startA endAngle: endA clockwise: YES];
    [path1 addLineToPoint: Center];
    
    // add the path to the context
    CGContextAddPath (CTX, path1.CGPath);
    [[UIColor greenColor] SET];
    // render to view the context
    CGContextFillPath (CTX);
    
    
    // third sector
    startA = endA;
    angle = 25/2 * 100.0 * M_PI;
    endA + = startA angle;
    * = Path2 UIBezierPath [UIBezierPath bezierPathWithArcCenter: Center RADIUS: RADIUS startAngle: startA endAngle: endA clockwise: YES];
    [path2 addLineToPoint: Center];
    
    // add the path to the context
    CGContextAddPath (CTX, path2.CGPath);
    [[UIColor blueColor ] SET];
    // render the view context
    CGContextFillPath (ctx);

Published 368 original articles · won praise 22 · Views 200,000 +

Guess you like

Origin blog.csdn.net/BianHuanShiZhe/article/details/104996054