iOS绘图圈百分比状态的路径

时间:2014-03-06 07:08:39

标签: ios drawing uibezierpath cashapelayer

我尝试为给定的百分比值画一个圆圈(就像我有25%我只画了四分之一的圆圈)。目前我只能在我的视野中画出一个完整的圆圈。对我的问题有任何想法吗?

代码atm:

- (UIBezierPath *)makeCircleAtLocation:(CGPoint)location radius:(CGFloat)radius
{
    self.circleCenter = location;
    self.circleRadius = radius;

    UIBezierPath *path = [UIBezierPath bezierPath];
    [path addArcWithCenter:self.circleCenter
                    radius:self.circleRadius
                startAngle:0.0
                  endAngle:M_PI * 2.0
                 clockwise:YES];


    return path;
}

- (void)drawCircleForLocation{
    CGPoint location = CGPointZero;
    location.x = self.frame.size.width/2;
    location.y = self.frame.size.height/2;

    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = [[self makeCircleAtLocation:location radius:9] CGPath];
    shapeLayer.strokeColor = [[UIColor whiteColor] CGColor];
    shapeLayer.fillColor = nil;
    shapeLayer.lineWidth = 1.5;

    [self.layer addSublayer:shapeLayer];
}

1 个答案:

答案 0 :(得分:2)

2 Pi RAD = 360°=全圆。 25%的圆= 2 PI * 25%

  - (UIBezierPath *)makeCircleAtLocation:(CGPoint)location radius:(CGFloat)radius percent:(CGFloat)percent
    {
        self.circleCenter = location;  //????
        self.circleRadius = radius;    //????

        UIBezierPath *path = [UIBezierPath bezierPath];
        [path addArcWithCenter:location
                        radius:radius
                    startAngle:0.0
                      endAngle:((M_PI * 2.0) * percent)
                     clockwise:YES];

        [path addLineToPoint:location];
        [path closePath];
        return path;
    }