绘制方法需要重写- (void)drawRect:(CGRect)rect,使用UIBezierPath绘制圆形动画路径,调用stroke进行绘制,如下:
- (void)drawRect:(CGRect)rect
{
UIBezierPath *path = [[UIBezierPath alloc] init];
path.lineWidth = 10.0;
[[UIColor colorWithRed:0/255.0 green:191/255.0 blue:255/255.0 alpha:1] set];
path.lineCapStyle = kCGLineCapRound;
path.lineJoinStyle = kCGLineJoinRound;
CGFloat radius = (MIN(rect.size.width, rect.size.height) - 10.0) * 0.5;
[path addArcWithCenter:(CGPoint){rect.size.width * 0.5, rect.size.height * 0.5} radius:radius startAngle:M_PI * 1.5 endAngle:M_PI * 1.5 + M_PI * 2 * _progress clockwise:YES];
[path stroke];
}