iOS - 带圆角的饼图进度条

iOS - Pie progress bar with rounded corners

我需要根据这个设计实现一个进度条:

如您所见,钢筋本身有一个圆角半径。

这是我当前代码的样子:

那么,该怎么做呢? 这是我当前的代码:

- (void)animateProgressBarToPercent:(float)percent
{
    if (percent > 1.0f) return;

    int radius = 42.7f;
    int strokeWidth = 7.f;
    CGColorRef color = [UIColor someColor].CGColor;
    int timeInSeconds = percent * 5;

    CGFloat startAngle = 0;
    CGFloat endAngle = percent;

    CAShapeLayer *circle = [CAShapeLayer layer];
    circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius) cornerRadius:radius].CGPath;
    circle.position = CGPointMake(self.center.x - radius, self.center.y + strokeWidth);
    circle.fillColor = [UIColor clearColor].CGColor;
    circle.strokeColor = color;
    circle.lineWidth = strokeWidth;
    circle.strokeEnd = endAngle;

    [self.layer addSublayer:circle];

    CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    drawAnimation.duration            = timeInSeconds;
    drawAnimation.repeatCount         = 1.0;
    drawAnimation.removedOnCompletion = NO;

    drawAnimation.fromValue = [NSNumber numberWithFloat:startAngle];
    drawAnimation.toValue   = [NSNumber numberWithFloat:endAngle];

    drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    [circle addAnimation:drawAnimation forKey:@"drawCircleAnimation"];
}
circle.lineCap = kCALineCapRound

只需设置您 CAShapeLayer

的这个 属性