简体   繁体   English

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

[英]iOS drawing circle Path for percent state

i try to draw a circle for a given percent value (like if i have 25% i just draw a quarter of the circle). 我尝试绘制一个给定百分比值的圆(例如,如果我有25%,我就画一个圆的四分之一)。 At the moment im just able to draw a full circle within my view. 目前,我只能在我的视线范围内画出一个完整的圆圈。 Any ideas to my problem? 对我的问题有什么想法吗?

Code atm: 代码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];
}

2 Pi RAD = 360° = full circle. 2 Pi RAD = 360°=整圈。 25% of circle = 2 PI * 25% 圆的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;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM