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];
时间: 2024-10-13 12:25:33