Iphone 用于显示进度的圆圈内的drawRect圆圈
我试着用一个圆圈填充另一个圆圈来展示进步。有人能帮我做到这一点吗?我可能走错了方向。 这是我的密码:Iphone 用于显示进度的圆圈内的drawRect圆圈,iphone,ios,geometry,progress,drawrect,Iphone,Ios,Geometry,Progress,Drawrect,我试着用一个圆圈填充另一个圆圈来展示进步。有人能帮我做到这一点吗?我可能走错了方向。 这是我的密码: - (void)drawRect:(CGRect)rect { rect = CGRectMake(0, 400, 500, 500); [[UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 500, 500) cornerRadius:50.0] addClip]; CGContextRef contex
- (void)drawRect:(CGRect)rect
{
rect = CGRectMake(0, 400, 500, 500);
[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 500, 500) cornerRadius:50.0] addClip];
CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(contextRef, 2.0);
CGContextSetRGBFillColor(contextRef, 111/255.0f, 116/255.0f, 128/255.0f, 1.0);
CGRect circlePoint = (CGRectMake(0, 0, rect.size.width, rect.size.height));
CGContextFillEllipseInRect(contextRef, circlePoint);
CGContextBeginPath(contextRef);
float c = 20; //Number that should cause the green progress to increase and decrease
CGContextAddArc(contextRef, 250, 250, 250, 0, M_PI, 0);
CGContextClosePath(contextRef); // could be omitted
UIColor *color = [UIColor greenColor];
CGContextSetFillColorWithColor(contextRef, color.CGColor);
CGContextFillPath(contextRef);
}
下面是它现在的屏幕截图。我基本上希望能够使用我的float c来控制内部的绿色进程代码>变量
我试过玩CGContextAddArc
,但当“c”增大时,我无法达到圆圈的大小,而当我减小“c”的值时,我无法达到圆圈的大小
使用c表示从何处到何处
// draw the pie part
CGContextMoveToPoint(_viewContext, centerX, centerY);
CGContextAddArc(_viewContext, centerX, centerY, pieRadius, radians(startDegrees), radians(endDegrees), 0);
CGContextClosePath(_viewContext);
CGContextFillPath(_viewContext);
- startDegrees=0
- 端度=c
- _viewContext=contextRef
- centerX/CenterY=边界中心
- PieRadius=所需半径:D(像素IIRC)
将deg转换为rad
#define pi 3.14159265
double radians(double percentage)
{
return (percentage/100)*360 * (pi/180);
}
它起作用了!你知道为什么进展不是直线上升吗?它从侧面随机上升。谢谢你的帮助!这里有一些截图:25%:50%:75%:啊,现在我知道你想要什么了。你想让它从下到上填满圆圈。。有点像“glas”——这不是随机的。它从RAD=0开始。如果你想从底部填满它,只需把它全部画成一个矩形。然后把它剪成圆形