【问题标题】:iOS drawing circle Path for percent state百分比状态的iOS绘制圆圈路径
【发布时间】:2014-03-06 07:08:39
【问题描述】:

我尝试为给定的百分比值绘制一个圆(例如,如果我有 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];
}

【问题讨论】:

    标签: ios drawing uibezierpath cashapelayer


    【解决方案1】:

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

    【讨论】:

    • 我在return path; 行之前错过了[path closePath];
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    相关资源
    最近更新 更多