Objective c 在目标C中画一个饼
我用下面的代码在目标C中画了一条弧Objective c 在目标C中画一个饼,objective-c,cocoa,graphics,Objective C,Cocoa,Graphics,我用下面的代码在目标C中画了一条弧 [newPath appendBezierPathWithArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle]; 现在我想画两条从中心到弧两端的线。我该怎么做?我可以用以下代码绘制一面: [newPath lineToPoint:center]; 但是另一面呢。我现在没有机会测试它,但是你可以试试这样的东西 #import "math.h"
[newPath appendBezierPathWithArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle];
现在我想画两条从中心到弧两端的线。我该怎么做?我可以用以下代码绘制一面:
[newPath lineToPoint:center];
但是另一面呢。我现在没有机会测试它,但是你可以试试这样的东西
#import "math.h"
[newPath moveToPoint:center];
[newPath addLineToPoint:CGPointMake(center.x + radius * cos(endAngle * M_PI / 180),
center.y + radius * sin(endAngle * M_PI / 180))];
[newPath moveToPoint:center];
[newPath addLineToPoint:CGPointMake(center.x + radius * cos(startAngle * M_PI / 180),
center.y + radius * sin(startAngle * M_PI / 180))];
绘制饼图最简单的方法是使用以下事实:appendBezierPathWithArcWithCenter:…
绘制饼图
从当前点到圆弧起点的直线:
// Start at the center of the circle:
[newPath moveToPoint:center];
// This draws a line from the center to the starting point of the arc AND the arc:
[newPath appendBezierPathWithArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle];
// Closing the path draws a line from the end point of the arc back to the center:
[newPath closePath];
使用三角学计算圆弧的起点,然后当光标位于中心时,
[newPath lineToPoint:startingPoint]
。在iOS SDK中,等效方法为addArcWithCenter: