2012-04-12 5 views
0

두 점 사이에 선을 그립니다. 여기 내 코드가있다. 하지만 상황에 맞는 메모리 당신은 방법 drawRect:에 UIView의 서브 클래스 내에서 코드를 호출 할 필요가 0두 개의 다른 점 사이에 선을 그립니다.

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

입니다. UIGraphicsGetCurrentContext()은 사용자가 도면 컨텍스트에 있지 않을 때 NULL (0)을 가져옵니다.

docs을 확인할 수도 있습니다.

관련 문제