问题描述
我是一名新手ios程序员。在我的一个项目中,我需要绘制一个圆圈,其中圆圈的不同部分将填充不同的颜色。我可以绘制圆圈。但我无法确定圈子的不同部分用不同的颜色填充它们。这是一个截图,用于说明我想要绘制的内容。
I am a novice ios programmer.In one of my project i need to draw a circle in which different portion of the circle would be filled up with different colors.I can draw the circle.But i am not being able to determine the different portion of the circle and fill them with different color.Here is an screenshot to clarify what i want to draw.
我们将不胜感激。
推荐答案
您可以使用 UIBezierPath
,其方法 addArcWithCenter:radius:startAngle:endAngle:顺时针:
您可以在其中指定半径,中心和角度。代码看起来像这样,以绿色绘制四分之一圆:
You can use UIBezierPath
which has a method addArcWithCenter:radius:startAngle:endAngle:clockwise:
where you can specify radius, center and angles. The code could look like this which draws a quarter of a circle in green:
CGPoint center = CGPointMake(CGRectGetWidth(self.bounds) / 2.f, CGRectGetHeight(self.bounds) / 2.f);
CGFloat radius = center.x - 10.f;
UIBezierPath *portionPath = [UIBezierPath bezierPath];
[portionPath moveToPoint:center];
[portionPath addArcWithCenter:center radius:radius startAngle:0.f endAngle:M_PI_2 clockwise:YES];
[portionPath closePath];
[[UIColor greenColor] setFill];
[portionPath fill];
UIBezierPath *portionPath1 = [UIBezierPath bezierPath];
[portionPath1 moveToPoint:center];
[portionPath1 addArcWithCenter:center radius:radius startAngle:M_PI_2 endAngle:M_PI clockwise:YES];
[portionPath1 closePath];
[[UIColor blueColor] setFill];
[portionPath1 fill];
当然你也可以考虑使用像。
Of course you can also consider to use a library like CorePlot.
这篇关于画一个圆圈,用不同的颜色填充不同的部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!