[圆形进度条]UIBezierPath画图基础实例与CAShapeLayer

1、圆形进度条

 效果图:


[圆形进度条]UIBezierPath画图基础实例与CAShapeLayer_第1张图片

函数代码:

直接添加到 view.layer  直接调用方法就可以。

/**

*  画圆进度条

*/

-(void)drawCircle

{

CAShapeLayer *circleLayer=[CAShapeLayer layer];

//设置位置

circleLayer.lineWidth=2.0;

circleLayer.fillColor=[UIColor whiteColor].CGColor;

//线的颜色

circleLayer.strokeColor=[UIColor redColor].CGColor;

//路径

UIBezierPath *path=[UIBezierPath bezierPath];//bezierPathWithOvalInRect:CGRectMake(self.frame.size.width/4, self.frame.size.height/2, 200, 200)];

[path addArcWithCenter:CGPointMake(self.frame.size.width/2., self.frame.size.height/2.) radius:100 startAngle:0 endAngle:2*M_PI clockwise:YES];

circleLayer.path=path.CGPath;

[self.layer addSublayer:circleLayer];

circleLayer.strokeStart=0.0;

circleLayer.strokeEnd=.9;

CABasicAnimation *pathAnima=[CABasicAnimation animationWithKeyPath:@"strokeEnd"];

pathAnima.duration=3;

pathAnima.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

pathAnima.fromValue=[NSNumber numberWithFloat:0.];

pathAnima.toValue=[NSNumber numberWithFloat:1.];

pathAnima.fillMode=kCAFillModeForwards;

pathAnima.removedOnCompletion=NO;

[circleLayer addAnimation:pathAnima forKey:@"path"];

//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

//

//        [UIView animateWithDuration:20 animations:^{

//            circleLayer.strokeEnd=1;

//        }];

//

//    });

}

你可能感兴趣的:([圆形进度条]UIBezierPath画图基础实例与CAShapeLayer)