简体   繁体   English

lineWidth无法正确呈现贝塞尔曲线的宽度

[英]lineWidth not rendering Bezier curve width correctly

I am using lineWidth to create a circle with stroke width 4. I am using UIBezierPath for creating the circle. 我正在使用lineWidth创建一个笔触宽度为4的圆。我正在使用UIBezierPath创建该圆。 But, due to some reason, lineWidth is always rendering a circle with a thin stroke no matter what value I assign to lineWidth. 但是,由于某些原因,无论我为lineWidth分配了什么值,lineWidth始终都会绘制一个细笔画的圆。 I have also tried to put path.lineWidth = 100.0, but no change in stroke width. 我也尝试过放置path.lineWidth = 100.0,但是笔触宽度没有变化。

This is my code: 这是我的代码:

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];

I googled a lot, but could not find any solution to this problem. 我在Google上搜索了很多,但是找不到解决此问题的任何方法。

You need to set the stroke width before you actually stroke the path: 在实际描边路径之前,需要设置描边宽度:

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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM