Draw ellipse with start and end angle in Objective-C

前端 未结 3 1311
轻奢々
轻奢々 2021-02-09 06:32

I am writing an iPad app in which I am rendering XML objects that represent shapes into graphics on the screen. One of the objects I am trying to render is arcs. Essentially the

3条回答
  •  梦如初夏
    2021-02-09 07:05

    You can probably achieve what you want by setting up a clip path around the drawing of the ellipse.

    CGContextSaveGState(theCGContext);
    CGPoint center = CGPointMake(x + width / 2.0, y + height / 2.0);
    UIBezierPath* clip = [UIBezierPath bezierPathWithArcCenter:center
                                                        radius:max(width, height)
                                                    startAngle:startAngle
                                                      endAngle:endAngle
                                                     clockwise:YES];
    [clip addLineToPoint:center];
    [clip closePath];
    [clip addClip];
    
    UIBezierPath *arc = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(x, y, width, height)];
    [[UIColor blackColor] setStroke];
    [arc stroke];
    
    CGContextRestoreGState(theCGContext);
    

    The exact radius for the clipping isn't important. It needs to be big enough so it only clips the ellipse at the ends, not through the desired arc.

提交回复
热议问题