lineWidth 未正确渲染贝塞尔曲线宽度

lineWidth not rendering Bezier curve width correctly

我正在使用 lineWidth 创建笔划宽度为 4 的圆。我正在使用 UIBezierPath 创建圆。但是,由于某种原因,无论我为 lineWidth 分配什么值,lineWidth 总是渲染一个带有细笔划的圆。我也试过 path.lineWidth = 100.0,但笔划宽度没有变化。

这是我的代码:

UIGraphicsBeginImageContextWithOptions(CGSizeMake(progressView.frame.size.width, progressView.frame.size.height), NO, 0.0);

    [[UIColor colorWithRed:246.0/255.0 green:80.0/255.0 blue:36.0/255.0 alpha:1.0] setStroke];

    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(progressView.frame.size.width/2 ,progressView.frame.size.height/2) radius:progressView.frame.size.width/2 - 5 startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(angle) clockwise:YES];
    [path stroke];
    path.lineWidth = 4;
UIImage* pathImg = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    [progressView setImage:pathImg];

我用谷歌搜索了很多,但找不到解决这个问题的方法。

您需要在实际描边路径之前设置描边宽度:

UIGraphicsBeginImageContextWithOptions(CGSizeMake(progressView.frame.size.width, progressView.frame.size.height), NO, 0.0);
[[UIColor colorWithRed:246.0/255.0 green:80.0/255.0 blue:36.0/255.0 alpha:1.0] setStroke];
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(progressView.frame.size.width/2 ,progressView.frame.size.height/2) radius:progressView.frame.size.width/2 - 5 startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(angle) clockwise:YES];
path.lineWidth = 4;
[path stroke];
UIImage* pathImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[progressView setImage:pathImg];