画出没有 - (void)drawRect:(CGRect)rect方法的行?
问题描述:
我想在UIView内制作图表。事情是这样的: 画出没有 - (void)drawRect:(CGRect)rect方法的行?
有绘制的线条比使用这种方法更简单的方法:
-(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);
}
?
答
您可以尝试使用UIBezierPath
类:
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:startPoint];
[path addLineToPoint:endPoint];
[path stroke];
如果您需要绘制图表时,尽量使用CorePlot - 绘图框架。
试试'PCLineChartView' [链接](https://github.com/honcheng/iOSPlot/tree/master/iOSPlot),一个简单的方法来绘制这样的图表 – Akhilrajtr 2014-08-28 11:37:47
好的谢谢,我会检查出来。 – Alan 2014-08-28 11:39:50