在Objective-c中绘制圆圈 [英] Drawing circle in Objective-c

查看:165
本文介绍了在Objective-c中绘制圆圈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iPhone编程的初学者。我需要创建如图1所示的圆圈,它应该分成六个不同的部分,有四个不同的级别(见图1)。此外,我需要根据给定的数据创建一个圆圈,如图2所示。每个零件都应该可以单击以缩放特定零件(参见图3)。

I am a beginner in iPhone programing. I need to create circles like Figure 1, where it should be divided in six different parts with four different levels (see Figure 1). Furthermore I need to create a circle according to a given data as it is shown on Figure 2. Each part should be click-able to zoom the specific part (see Figure 3).


< br> 图1:说明六种不同的颜色,其中两种颜色分为一种,其余四种颜色分为三种。



图2:显示不同级别的不同类别的结果。$


图3 :选择类别的缩放视图。


我有一个故事板,可以加载自定义UIView并使用drawRect方法绘制圆圈。


Figure 1: Illustrates six different colors, where two of them are divided in one and the rest four of them are divided in three parts.

Figure 2: Shows the results of different categories in different levels.

Figure 3: Is a zoomed vision of chosen category.

I have a storyboard which loads loads a custom UIView and using drawRect method to draw the circle.

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

The question is now, how to create the pie chart like the figures?

我尝试了很多东西并且可以使用一些指导 - 或者请举一个例子。

谢谢

I have tried lots of things and could use some guideness - or please give an example of this.
Thanks

推荐答案

饼图示例:

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);
}

这篇关于在Objective-c中绘制圆圈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆