Wingzero
Wingzero

Reputation: 9754

reuse UIBezierPath object

I want to draw an arc and circyle under the arc, and I am using UIBezierPath to do it.

However I want to use only one bezierPath, below code seems dummy. How can I combine the two beizerPath into one and draw the same chart?

- (void)drawBackGround {
    UIBezierPath *bgPath = [UIBezierPath bezierPath];
    UIColor *color = [UIColor colorWithHex:BG_ARC_COLOR];
    [color set];
    [bgPath addArcWithCenter:self.center radius:BG_RADIUS startAngle:START_ANGLE endAngle:END_ENGLE clockwise:ANTY_CLOCK_WISE];
    bgPath.lineWidth = BG_ARC_WIDTH;
    bgPath.lineCapStyle = kCGLineCapRound;
    bgPath.lineJoinStyle = kCGLineCapRound;
    [bgPath stroke];
    UIBezierPath *circylePath = [UIBezierPath bezierPath];
    [circylePath moveToPoint:self.center];
    [circylePath addArcWithCenter:self.center radius:BG_CIRCYLE_RADIUS startAngle:0 endAngle:2 * M_PI clockwise:CLOCK_WISE];
    [circylePath addLineToPoint:self.center];
    [circylePath fill];
}

Upvotes: 1

Views: 453

Answers (1)

Michael
Michael

Reputation: 6899

Give this a try:

UIBezierPath *bgPath = [UIBezierPath bezierPath];
UIColor *color = [UIColor colorWithHex:BG_ARC_COLOR];
[color set];
[bgPath addArcWithCenter:self.center radius:BG_RADIUS startAngle:START_ANGLE endAngle:END_ENGLE clockwise:ANTY_CLOCK_WISE];
bgPath.lineWidth = BG_ARC_WIDTH;
bgPath.lineCapStyle = kCGLineCapRound;
bgPath.lineJoinStyle = kCGLineCapRound;
[bgPath stroke];

[bgPath removeAllPoints];

[bgPath moveToPoint:self.center];
[bgPath addArcWithCenter:self.center radius:BG_CIRCYLE_RADIUS startAngle:0 endAngle:2 * M_PI clockwise:CLOCK_WISE];
[bgPath addLineToPoint:self.center];
[bgPath fill];

Upvotes: 1

Related Questions