4
我试图用UIBezierPath画一个饼图,和我很接近的话,但是,我有一个问题,因为你可以在附截图看到 下面是我使用的代码:绘制饼图与UIBezierPath
-(void)drawRect:(CGRect)rect
{
CGRect bounds = self.bounds;
CGPoint center = CGPointMake((bounds.size.width/2.0), (bounds.size.height/2.0));
NSManagedObject *gameObject = [SCGameManager sharedInstance].gameObject;
int playerNumber = 0;
int totalOfPlayers = [(NSSet*)[gameObject valueForKey:@"playerColors"] count];
float anglePerPlayer = M_PI*2/totalOfPlayers;
for (NSManagedObject *aPlayerColor in [gameObject valueForKey:@"playerColors"]){
//Draw the progress
CGFloat startAngle = anglePerPlayer * playerNumber;
CGFloat endAngle = startAngle + anglePerPlayer;
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:self.frame. size.width/2 startAngle:startAngle endAngle:endAngle clockwise:YES];
UIColor *playerColor = [SCConstants getUIColorForPlayer:[[aPlayerColor valueForKey:@"colorIndex"] intValue]];
[playerColor set];
[path fill];
playerNumber++;
}
}
很显然,我只需要我的路径移动的圆心,然后将其关闭,但是当我添加以下代码行:
[path addLineToPoint:self.center];
[path closePath];
它吸引了一些奇怪的东西:
你知道我的代码出了什么问题吗?我根本不是贝塞尔的专家,所以任何帮助都是值得欢迎的!
谢谢!
看上去很好!非常感谢,修复它。 – 2013-03-17 14:32:36