gpt4 book ai didi

ios - iOS绘图圈百分比状态的路径

转载 作者:行者123 更新时间:2023-12-01 19:01:57 25 4
gpt4 key购买 nike

我尝试绘制一个给定百分比值的圆(例如,如果我有25%,我就画一个圆的四分之一)。目前,我只能在我的视线范围内画出一个完整的圆圈。对我的问题有什么想法吗?

代码atm:

- (UIBezierPath *)makeCircleAtLocation:(CGPoint)location radius:(CGFloat)radius
{
self.circleCenter = location;
self.circleRadius = radius;

UIBezierPath *path = [UIBezierPath bezierPath];
[path addArcWithCenter:self.circleCenter
radius:self.circleRadius
startAngle:0.0
endAngle:M_PI * 2.0
clockwise:YES];


return path;
}

- (void)drawCircleForLocation{
CGPoint location = CGPointZero;
location.x = self.frame.size.width/2;
location.y = self.frame.size.height/2;

CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = [[self makeCircleAtLocation:location radius:9] CGPath];
shapeLayer.strokeColor = [[UIColor whiteColor] CGColor];
shapeLayer.fillColor = nil;
shapeLayer.lineWidth = 1.5;

[self.layer addSublayer:shapeLayer];
}

最佳答案

2 Pi RAD = 360°=整圈。
圆的25%= 2 PI * 25%

  - (UIBezierPath *)makeCircleAtLocation:(CGPoint)location radius:(CGFloat)radius percent:(CGFloat)percent
{
self.circleCenter = location; //????
self.circleRadius = radius; //????

UIBezierPath *path = [UIBezierPath bezierPath];
[path addArcWithCenter:location
radius:radius
startAngle:0.0
endAngle:((M_PI * 2.0) * percent)
clockwise:YES];

[path addLineToPoint:location];
[path closePath];
return path;
}

关于ios - iOS绘图圈百分比状态的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22217526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com