iOS 贝赛尔 圆形进度条

    UIBezierPath *aPth = [UIBezierPath bezierPathWithArcCenter:CGPointMake(55, 65.f) radius:50.f startAngle:-M_PI_2 endAngle:M_PI_2 clockwise:YES];
    aPth.lineWidth = 5.0f;
    aPth.lineCapStyle = kCGLineCapRound;
    aPth.lineJoinStyle = kCGLineJoinRound;
    [[UIColor redColor] setStroke];
    [[UIColor orangeColor] setFill];
    [aPth stroke];

  

进度条动画


// 第一、 UIBezierPath 绘制线段

    UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(55, 65.f) radius:50.f startAngle:-M_PI_2 endAngle:M_PI_2*3 clockwise:YES];

 

    // 第二、 UIBezierPath CAShapeLayer 关联

  CAShapeLayer *progressLayer = [ CAShapeLayer layer];

  progressLayer.path         = circlePath. CGPath ;

    progressLayer.fillColor     = [UIColor clearColor].CGColor;

  progressLayer.strokeColor   = [ UIColor redColor]. CGColor ;

  progressLayer.lineWidth     = 5.0f;

    progressLayer.lineCap      = kCALineCapRound;

 

    //第三,动画

    CABasicAnimation *ani = [ CABasicAnimation animationWithKeyPath : NSStringFromSelector ( @selector (strokeEnd))];

    ani. fromValue = @0 ;

  ani. toValue = @1 ;

 ani. duration = 5 ;
  [progressLayer addAnimation :ani forKey : NSStringFromSelector ( @selector (strokeEnd))];

 [view. layer addSublayer :progressLayer];

 

posted on 2015-04-13 00:33  永远的冰蝴蝶  阅读(330)  评论(0)    收藏  举报

导航