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",@"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];

我得到的输出如下图所示:Graph

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

最佳答案

看起来您没有正确关闭路径,因此第一个点和最后一个点之间是直线。您应该对最后三个点使用 addLineToPoint 而不仅仅是 moveToPoint,然后我想您就会到达那里。

关于iphone - 在 UIBezierPath 内填充颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17585833/

相关文章:

ios - iPhone 上工具栏图标的合适大小是多少

iphone - 当应用程序进入 bkgr 时 uialertview 会发生什么

ios - 如何将 UIBezierPath 带到 MKAnnotation 对象的后面?

swift - 如何在 Swift 中使用 Bezier 路径连接 3D 空间中的两个 SCNSphere?

swift - 虚线 UIBezierPath 子路径连接点

ios - 重用 UIBezierPath 对象

ios - 以编程方式停止向 iPhone 发送短信

iphone - 从iPhone上的远程sql表获取数据

iphone - 为什么我无法从 UITableView 单元格转至详细 View ?

swift - 将图层蒙版设置为 UIBezierPath super View