我想在UIView中制作一个图表。像这样的东西:
绘制线条的方法比使用此方法更简单:
-(void)drawRect:(CGRect)rect{
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
// Draw them with a 2.0 stroke width so they are a bit more visible.
CGContextSetLineWidth(context, 2.0f);
CGContextMoveToPoint(context, 0.0f, 0.0f); //start at this point
CGContextAddLineToPoint(context, 20.0f, 20.0f); //draw to this point
// and now draw the Path!
CGContextStrokePath(context);
}
答案 0 :(得分:0)
为什么不尝试UIBezierPath
Apple的高级实现。
只需参阅UIBezierPath - Apple Doc了解更多信息
答案 1 :(得分:0)
您可以尝试使用UIBezierPath
类:
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:startPoint];
[path addLineToPoint:endPoint];
[path stroke];
如果您需要绘制图表,请尝试使用CorePlot - 绘图框架。