2012-04-12 21 views
0

2点の間に線を描きたい。ここに私のコードです。しかし、コンテキストメモリが02つの異なる点の間に線を描く

CGContextRef context = UIGraphicsGetCurrentContext(); 

     CGContextSetLineWidth(context, 2.0); 

     CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); 

     CGFloat components[] = {0.0, 0.0, 1.0, 1.0}; 

     CGColorRef color = CGColorCreate(colorspace, components); 

     CGContextSetStrokeColorWithColor(context, color); 

     CGContextMoveToPoint(context, 0, 0); 
     CGContextAddLineToPoint(context, 300, 400); 

     CGContextStrokePath(context); 
     CGColorSpaceRelease(colorspace); 
     CGColorRelease(color); 
+0

どのような方法でこれを試していますか?、 – Vignesh

+0

コンテキストメモリとは何ですか?あなたの 'context'変数が' nil'ではないと確信していますか? – Alexander

+0

重複している可能性があります:http://stackoverflow.com/questions/1878821/how-to-draw-line-between-two-points – Devang

答えて

2

であるあなたは、この方法drawRect:でUIViewのサブクラス内のコードを呼び出す必要があります。 UIGraphicsGetCurrentContext()は、あなたが描画コンテキストにないときにNULL(0)を取得します。

docsもチェックしてください。

関連する問題