Iphone UIBezierPath内的填充颜色

Iphone UIBezierPath内的填充颜色,iphone,uibezierpath,Iphone,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"

我想使用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];
NSMutableArray*graphData=[NSMutableArray alloc]initWithObjects:[NSArray arrayWithObjects:“2013-06-26”,“46”,无],[NSArray arrayWithObjects:“2013-06-27”,“37”,无],[NSArray arrayWithObjects:“2013-06-28”,“96”,无],[NSArray arrayWithObjects:“2013-06-29”,“29”,无],[NSArray arrayWithObjects:“2013-06-30”,“29”,无],[NSArray阵列及其对象:@“2013-07-01”,“24”,无],无];
UIBezierPath*aPath=[UIBezierPath bezierPath];
[[UIColor blackColor]设定行程];
[[UIColor redColor]setFill];
[aPath moveToPoint:CGPointMake(10,kGraphBottom-[[graphData objectAtIndex:0]objectAtIndex:1]floatValue]);
对于(int i=1;i
我得到的输出如下图所示:


如何填充图形和x、y轴之间的颜色?

看起来您没有正确闭合路径,因此第一个点和最后一个点之间是直线。您应该使用
addLineToPoint
作为最后三个点,而不仅仅是
moveToPoint
,然后我认为您会在那里。

据我所知nd,您希望绘制该路径,但填充不同的区域(路径和轴之间的区域)


为此,您必须使用两条路径。您正在绘制的一条用于笔划,另一条用于填充。同时构建两条路径,但从坐标系的原点开始填充路径,并在图形的开头添加一条线。继续向两条路径添加线,并在最后向x轴添加一条线以表示t他填写路径,关闭填写路径,您就完成了。

您的问题是什么?编辑了问题。请read@Herçules:谢谢,你有什么解决办法吗?我不能使用addlinetopoint,因为我不想在那里添加一行……我希望你能得到itaddLineToPoint,它只是移动不可见的光标,但不会向你的路径添加任何内容,所以不会做任何事情。如果您只想填充图形下的所有内容,则需要使用addLineToPoint,从最后一个点垂直到轴,沿x轴水平,然后垂直到第一个点,这是使用moveToPoint时的第一个点。如果您只想让图形顶部显示为黑色,则在不添加任何内容的情况下绘制路径这些点或先关闭路径。然后添加3行并填充。