我希望能够仅使用 Apple 框架来绘制图表。
这可能只使用CoreGraphics,还是我需要使用任何其他框架?
我不想使用任何第三方框架来绘制图表。
是的,当然有可能。像这样的图表只是一条线。您可以使用 UIBezierPath 或 CGPath 来绘制它。通常,您的图表上有一个点数组,然后在构建路径时只需向每个点添加线。
WWDC 2011 会议 129介绍了如何绘制 Stocks 应用程序中的图形并使其“花哨”,所有这些都使用核心图形。
这将是使用 CoreGraphics 执行某些操作的示例代码
CGContextBeginPath(context);
CGContextMoveToPoint(context, startX, startY);
CGContextAddLineToPoint(context, nextX, nextY);
// [...] and so on, for all line segments
CGContextSetLineWidth(context, 2);
CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] cgColor]);
CGContextStrokePath(context);
如果你想画轴、标签,我建议使用 CorePlot http://code.google.com/p/core-plot/