重用UIBezierPath对象

时间:2015-03-16 08:42:03

标签: ios uibezierpath

我想在弧下画一个圆弧和圆弧,我正在使用UIBezierPath来做它。

但是我想只使用一个bezierPath,下面的代码似乎是虚拟的。如何将两个beizerPath组合成一个并绘制相同的图表?

- (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];
}

1 个答案:

答案 0 :(得分:1)

尝试一下:

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];