2013-09-04 2 views
0

나는이 두 줄로 줄을 옮기고 추가하고있다.ios에서 line 용 CGContext를 제거하는 방법은 무엇입니까?

CGContextMoveToPoint(context, 20, 185); 
    CGContextAddLineToPoint(context, 20, 185); 

나는 어떻게 선을 제거 할 수 있음을 알고 싶어 (CGContextAddLineToPoint (문맥, 20, 185)와 같은; // addline). 내 배열 == 2 인 경우 선 색상을 이동하거나 지울 때 선을 제거하고 싶습니다.

내 선 색상은 선명하게 표시되거나 앞으로 이동하면 선을 제거합니다.

모든 의견이나 제안을 환영합니다.

+0

"라인 삭제"란 무엇을 의미합니까? 'array == 2'는 무엇을해야합니까? 모든 포인트가 동일하다는 점만 복사 및 붙여 넣기 버그입니까? –

+0

https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html#//apple_ref/c/func/CGContextClearRect – iPatel

답변

0

drawRect: 방법을 사용하는 동안에는 선을 그려야 할 필요가있는 경우 간단히 그릴 수 있고 원하는 경우 선을 그릴 수 있습니다. drawRect: 메서드는 여러 번 호출되며 드로잉을 시작하기 전에 본질적으로 "지워집니다". 따라서 코드는 다음과 같을 수 있습니다.

- (void)drawRect:(CGRect)rect { 
    // other drawing code and declaration of array variable... 
    if ([array count] == 2) { 
     CGContextMoveToPoint(context, 20, 185); 
     CGContextAddLineToPoint(context, 20, 185); 
    } 
} 
0

동일한 문제가 발생했습니다. 직접적으로 나는 그것을 할 수 없다. 그래서 나는 아래에서 약간의 까다로운 논리를 사용했고 나를 위해 일했다. 힌트를 드리겠습니다.이 논리가 도움이되기를 바랍니다.

내가 밑줄 버튼 내가 그것을 제거 할 필요가 일부 일치하는 경우에, 그래서 방법을의 drawRect 사용하여 그려, 그래서 나는 다음과 같이 수행

참고 : "isRemoveUnderLine은"내 사용자 정의 버튼 클래스에서 부울 속성입니다

if ([array count] == 2) { 
    myButton.isRemoveUnderLine = YES; 
    [myButton setNeedsDisplay]; //it will update your button context and call drawRect method again... 
} 

// 코드 아래의 drawRect 방법 :

- (void)drawRect:(CGRect)rect { 
    [super drawRect:rect]; 
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    if(_isRemoveUnderLine) 
     CGContextSetStrokeColorWithColor(context, [UIColor clearColor].CGColor); 
    else 
     CGContextSetStrokeColorWithColor(context, self.currentTitleColor.CGColor); 

... 
... 
} 

당신이 당신의 로그와 함께 해결하기 위해 몇 가지 힌트를 얻을 희망 ic !!!

관련 문제