在Objective-c中绘制圆

我是iPhone编程的初学者。 我需要创build如图1所示的圆圈,它应该分为六个不同的部分,分为四个不同的层次(见图1)。 此外,我需要根据给定的数据创build一个圆圈,如图2所示。每个部分都应该是可点击放大的特定部分(见图3)。

在这里输入图像说明
图1:显示了六种不同的颜色,其中两个分为一个,其余四个分为三个部分。
在这里输入图像说明
图2:显示不同级别的不同类别的结果。
在这里输入图像说明
图3:是select范畴的放大视野。

我有一个故事板载入一个自定义的UIView和使用drawRect方法来绘制圆。

现在的问题是,如何像数字一样创build饼图?

我已经尝试了很多东西,可以使用一些指导 – 或者请举一个例子。
谢谢

看看Quartz 2D编程指南 ,尤其是椭圆和剪切path部分。 其余的只是一些基本的math和几何。

您inheritanceUIView,使用Quartz 2D框架绘制您的圈子,并可能实现touchesBegan:touchesEnded:方法来处理在圆圈上的水龙头。

如果你以任何方式想要改变animation(比如放大最后一个图像中的一个分类),那么你应该尝试尽可能多地使用Core Animation。

看看这个关于使用Core Animation制作自定义animation饼图的精彩教程 。 我相信你可以修改它来得到你想要的。

另外,如果你不关心animation,而且只显示从状态跳转到状态的圆圈,那么Core Animation可能会让事情变得过于复杂,像Core Graphics这样的东西(就像其他提到的答案一样)可能是正确的方式去。

饼图例子:

 int sum = 0; CGFloat offset; CGFloat angleArray[numberOfSections+1]; CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetAllowsAntialiasing(context, true); CGContextSetShouldAntialias(context, true); for(int i=0; i<numberOfSections; i++) { sum += angle; } for(int i=0; i<numberOfSections; i++) { angleArray[i] = (float)((angle)/(float)sum)*(2*M_PI); CGContextMoveToPoint(context, radius, radius); if(i == 0) { CGContextAddArc(context, radius, radius, radius, 0, angleArray[i], 0); } else { CGContextAddArc(context, radius, radius, radius, offset, (offset+angleArray[i]), 0); } offset += angleArray[i]; CGContextSetFillColorWithColor(context, ((UIColor *)[hjulColorArray objectAtIndex:i]).CGColor); CGContextClosePath(context); CGContextFillPath(context); } 

其实我觉得这个修改后的答案从长远来看会更有帮助。 看看这些文件:

 CGPathAddLineToPoint CGPathAddArc 

这就是我以前所做的基本上正是你想要做的事情。