2014-03-06 11 views
1

我嘗試繪製一個給定的百分比值的圓圈(如果我有25%,我只畫了四分之一的圓圈)。此刻,我只能在我的視野內繪製一個完整的圈子。任何想法對我的問題?iOS繪圖圈百分比狀態的路徑

代碼大氣壓:

- (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

2裨RAD = 360°=全圓。圓= 2 PI * 25%的 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; 
    } 
+0

我已經錯過'[路徑closePath];'只是'返回路徑之前;'線 –