圆形进度条
- (void)drawRect:(CGRect)rect {
CGContextRef ctx = UIGraphicsGetCurrentContext();//获取上下文
CGPoint center = CGPointMake(100, 100); //设置圆心位置
CGFloat radius = 90; //设置半径
CGFloat startA = - M_PI_2; //圆起点位置
CGFloat endA = -M_PI_2 + M_PI * 2 * _progress; //圆终点位置_progress(0到1)
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES];
CGContextSetLineWidth(ctx, 10); //设置线条宽度
[[UIColor blueColor] setStroke]; //设置描边颜色
CGContextAddPath(ctx, path.CGPath); //把路径添加到上下文
CGContextStrokePath(ctx); //渲染
}
*******************************************************************************************************
***********************************
self.outLayer = [CAShapeLayer layer];
CGRect rect = {kLineWidth / 2, kLineWidth / 2,
frame.size.width - kLineWidth, frame.size.height - kLineWidth};
UIBezierPath *path = [UIBezierPathbezierPathWithOvalInRect:rect];
self.outLayer.strokeColor = [UIColor lightGrayColor].CGColor;
self.outLayer.lineWidth = kLineWidth;
self.outLayer.fillColor = [UIColor clearColor].CGColor;
self.outLayer.lineCap = kCALineCapRound;
self.outLayer.path = path.CGPath;
[self.layeraddSublayer:self.outLayer];
self.progressLayer = [CAShapeLayer layer];
self.progressLayer.fillColor = [UIColor clearColor].CGColor;
self.progressLayer.strokeColor = [UIColor blueColor].CGColor;
self.progressLayer.lineWidth = kLineWidth;
self.progressLayer.lineCap = kCALineCapRound;
self.progressLayer.path = path.CGPath;
[self.layeraddSublayer:self.progressLayer];
self.transform = CGAffineTransformMakeRotation(-M_PI_2);
self.progressLayer.strokeEnd = number / 100.0;