2 daffodilgirl DaffodilGirl 于 2013.07.11 16:26 提问

UIBezierPath充填颜色

我要用UIBezierPath在一个图表中充填颜色。目前我已经完成的代码:

NSMutableArray *graphData=[[NSMutableArray alloc] initWithObjects:[NSArray arrayWithObjects:@"2013-06-26",@"46", nil],[NSArray arrayWithObjects:@"2013-06-27",@"37", nil],[NSArray arrayWithObjects:@"2013-06-28",@"96", nil],[NSArray arrayWithObjects:@"2013-06-29",@"29", nil],[NSArray arrayWithObjects:@"2013-06-30",@"29", nil],[NSArray arrayWithObjects:@"2013-07-01",@"24", nil], nil];
    UIBezierPath *aPath = [UIBezierPath bezierPath];
    [[UIColor blackColor] setStroke];
    [[UIColor redColor] setFill];    
    [aPath moveToPoint:CGPointMake(10, kGraphBottom-[[[graphData objectAtIndex:0] objectAtIndex:1]floatValue])];    
    for (int i = 1; i < graphData.count; i++)
    {
        [aPath addLineToPoint:CGPointMake(10+50* (i), kGraphBottom-[[[graphData objectAtIndex:i] objectAtIndex:1]floatValue])];    
    }
    [aPath moveToPoint:CGPointMake(10+50*graphData.count , kGraphBottom)];
    [aPath moveToPoint:CGPointMake(10 , kGraphBottom)];
    [aPath moveToPoint:CGPointMake(10 , kGraphBottom-[[[graphData objectAtIndex:0] objectAtIndex:1]floatValue])];
     [aPath closePath];
    [aPath fill];
    [aPath stroke];

得到的结果如下:

CSDN移动问答

如何给图形和x,y坐标之间充填颜色?

Csdn user default icon
上传中...
上传图片
插入图片