2014-08-28 84 views
0

我想在UIView內製作圖表。事情是這樣的: enter image description here畫出沒有 - (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); 
} 

+0

試試'PCLineChartView' [鏈接](https://github.com/honcheng/iOSPlot/tree/master/iOSPlot),一個簡單的方法來繪製這樣的圖表 – Akhilrajtr 2014-08-28 11:37:47

+0

好的謝謝,我會檢查出來。 – Alan 2014-08-28 11:39:50

回答

0

您可以嘗試使用UIBezierPath類:

UIBezierPath *path = [UIBezierPath bezierPath]; 
[path moveToPoint:startPoint]; 
[path addLineToPoint:endPoint]; 
[path stroke]; 

如果您需要繪製圖表時,儘量使用CorePlot - 繪圖框架。