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

标签 ios objective-c uibezierpath bezier

我正在使用 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];

关于ios - lineWidth 未正确渲染贝塞尔曲线宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30689079/

相关文章:

ios - 无法将带有撇号的字符串插入 sqlite ios

swift - 如何将图像放置在 uiview 绘图之上(swift5)

ios - 如何在主应用程序目标中使用单元测试用例(作为 test_spec 添加到开发 pod)?

ios - 查询从 Parse DB 中检索当前登录用户的 BOOL,这将确定要转到的 segue

ios - 设置 currentPageIndicatorTintColor 的错误

ios - 相当于 override init(frame :CGRect) in Swift?

ios - 通过 subview 移动一个正方形

swift - 在315°圆弧上绘制圆角

android - 如何在 React Native 中的两点之间画一条线?

ios - 警告 : "Modifying state during view update, this will cause undefined behavior." in UIViewRepresentable