//draw background circle
UIBezierPath *backCircle = [UIBezierPath bezierPathWithArcCenter:CGPointMake(CGRectGetWidth(self.bounds) / 2, CGRectGetHeight(self.bounds) / 2)
radius:(CGRectGetWidth(self.bounds) - self.lineWidth) / 2
startAngle:(CGFloat) - M_PI_2 //(π/2)
endAngle:(CGFloat)(1.5 * M_PI)
clockwise:YES];
[self.backColor setStroke];
backCircle.lineWidth = self.lineWidth;
[backCircle stroke];
if (self.progress) {
//draw progress circle
UIBezierPath *progressCircle = [UIBezierPath bezierPathWithArcCenter:CGPointMake(CGRectGetWidth(self.bounds) / 2,CGRectGetHeight(self.bounds) / 2)
radius:(CGRectGetWidth(self.bounds) - self.lineWidth) / 2
startAngle:(CGFloat) - M_PI_2
endAngle:(CGFloat)(- M_PI_2 + self.progress * 2 * M_PI)
clockwise:YES];
[self.progressColor setStroke];
progressCircle.lineWidth = self.lineWidth;
[progressCircle stroke];
UIBezierPath *backCircle = [UIBezierPath bezierPathWithArcCenter:CGPointMake(CGRectGetWidth(self.bounds) / 2, CGRectGetHeight(self.bounds) / 2)
radius:(CGRectGetWidth(self.bounds) - self.lineWidth) / 2
startAngle:(CGFloat) - M_PI_2 //(π/2)
endAngle:(CGFloat)(1.5 * M_PI)
clockwise:YES];
[self.backColor setStroke];
backCircle.lineWidth = self.lineWidth;
[backCircle stroke];
if (self.progress) {
//draw progress circle
UIBezierPath *progressCircle = [UIBezierPath bezierPathWithArcCenter:CGPointMake(CGRectGetWidth(self.bounds) / 2,CGRectGetHeight(self.bounds) / 2)
radius:(CGRectGetWidth(self.bounds) - self.lineWidth) / 2
startAngle:(CGFloat) - M_PI_2
endAngle:(CGFloat)(- M_PI_2 + self.progress * 2 * M_PI)
clockwise:YES];
[self.progressColor setStroke];
progressCircle.lineWidth = self.lineWidth;
[progressCircle stroke];
}
注:draw arc 实质是画线, 弧度的的宽度。 bezierPathWithArcCenter: radius: startAngle : endAngle: clockwise:该方法是画圆线,是在沿着半径画圆线,但不填充圆。 画圆弧只需要设置lineWidth即可。