2011-01-16 5 views
2

점선 (중국 점)과 같은 특수한 형태의 선을 그릴 수 있습니까? 아래 코드로 그립니다.점선 (중국 점)과 같은 특수한 형태의 선 그리기

UIGraphicsBeginImageContext(self.view.frame.size); 
[drawImage.image drawInRect:CGRectMake(0, 0, 320, 480)]; 
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0); 
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.867, 0.867, 0.867, 1.0); 
CGContextBeginPath(UIGraphicsGetCurrentContext()); 
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), startPoint.x, startPoint.y); 
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), endPoint.x, endPoint.y); 
CGContextStrokePath(UIGraphicsGetCurrentContext()); 
CGContextFlush(UIGraphicsGetCurrentContext()); 
drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

답변

4

아마도 CGContextSetLineDash이 원하는 것일 수 있습니다. 그래픽 컨텍스트에서 점선의 패턴을 설정합니다.

CGContextSetLineWidth(context, 20.0); 
CGFloat dash[] = {0.0, 40.0}; 
CGContextSetLineCap(context, kCGLineCapRound); 
CGContextSetLineDash(context, 0.0, dash, 2); 
CGContextMoveToPoint(context, 10.0, 30.0); 
CGContextAddLineToPoint(context, 310.0, 30.0); 
CGContextStrokePath(context); 
+0

감사가 가능 내 편집을 참조하십시오 –

+0

원과 같은 다른 모양과 라인을 그릴을 겪었 :

void CGContextSetLineDash ( CGContextRef c, CGFloat phase, const CGFloat lengths[], size_t count ); 

이 예는 원 (: 20 점, 거리 : 40 점 직경)와 선을 그립니다 대답 – Felix