gpt4 book ai didi

ios - 如何在 IOS 的 ARC 中心添加文本?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:19:50 25 4
gpt4 key购买 nike

你好,我正在开发饼图应用程序。我想在圆弧中间添加文字。请显示我想要显示的图像。

image .

我想在以文本为中心的圆弧中添加 100 和 250。

这是我的代码

  int slicesCount = [self.datasource numberOfSlicesInPieChartView:self];

for (int i = 0; i < slicesCount; i++)
{
sum += [self.datasource pieChartView:self valueForSliceAtIndex:i];
}

float startAngle = - M_PI_2-30;
float endAngle = 0.0f;

for (int i = 0; i < slicesCount; i++)
{
double value = [self.datasource pieChartView:self valueForSliceAtIndex:i];
endAngle = startAngle + M_PI*2*value/sum;
CGContextAddArc(context, centerX, centerY, radius, startAngle, endAngle, false);
UIColor *drawColor = [self.datasource pieChartView:self colorForSliceAtIndex:i];
CGContextSetStrokeColorWithColor(context, drawColor.CGColor);
CGContextSetLineWidth(context, lineWidth);
NSString *str=[arrValue objectAtIndex:slicesCount];
CGContextShowTextAtPoint(context, 54, 63, [str UTF8String], str.length);// **how can i get X and Y coordinate**
CGContextStrokePath(context);
startAngle += M_PI*2*value/sum;
}

请帮忙。谢谢

最佳答案

好吧,您可以使用以下公式计算切片的中心:

...
endAngle = startAngle + M_PI*2*value/sum;
labelAngle = endAngle - startAngle;
labelX = centerX + radius * cos(labelAngle);
labelY = centerY + radius * sin(labelAngle);
...

然后在该点绘制文本(注意这些是标签中心的坐标)。

关于ios - 如何在 IOS 的 ARC 中心添加文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20321975/

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