2012-12-03 3 views
0

아래 코드를 사용하여 다각형을 그립니다. 내가 할 이미지는 다음과 같습니다 :iOS의 코어 그래픽을 사용하여 그린 선의 접합부에서 점이 나타나는 이유는 무엇입니까?

enter image description here

내가 사각형을 그리기 위해 사용하고 코드는 다음과 같습니다 :

CGContextRef currentContext = UIGraphicsGetCurrentContext(); 
[topLeftBoxBorderColor set]; 
CGContextSetLineWidth(currentContext, 1.0f); 
CGContextSetLineJoin(currentContext,kCGLineJoinMiter); 
CGContextMoveToPoint(currentContext, originXOfSubviews, originYOfSubviews); 
CGContextAddLineToPoint(currentContext, originXOfSubviews+widthOfBox, originYOfSubviews); 
CGContextAddLineToPoint(currentContext, originXOfSubviews+widthOfBox, originYOfSubviews+heightOfBox); 
CGContextAddLineToPoint(currentContext, originXOfSubviews, originYOfSubviews+heightOfBox); 
CGContextAddLineToPoint(currentContext, originXOfSubviews, originYOfSubviews); 
CGContextStrokePath(currentContext); 

모든 코너에 두 줄의 교차점에 흰색 점이있다. 이 점이 없게하는 방법이 있습니까?

UPDATE 1 :

나는 아래의 해결책을 알고 라인을 바탕으로 라인의 시작, 포인트가 변경 내가 기대하는 것을 얻을 수있다 폭. 그러나 다른 해결책이 있습니까?

업데이트 2 : 나는 다각형

나는보다 1 이하로 선폭을 설정 지금 같은 문제가 발생 그릴 아래의 코드를 사용하고

. 2 이상으로 설정하면 문제가 발생하지 않습니다.

CGContextRef context = UIGraphicsGetCurrentContext(); 

    CGContextSetLineWidth(context, 2.0); 

    CGContextSetStrokeColorWithColor(context, topLeftBoxBorderColor.CGColor); 

    CGRect rectangle = CGRectMake(originXOfSubviews,originYOfSubviews,widthOfBox,heightOfBox); 

    CGContextAddRect(context, rectangle); 

    CGContextStrokePath(context); 
+0

투명도와 색상을 사용합니까의 사각형 그릴 수 있습니까? – AlexWien

+0

나는 그것을 사용하지 않고있다. – Krishnan

+0

나는 더 이상 하얀 점이 보이지 않는다. 나는 접합부가 겹치는 것을 보았다. 어떤 점에서 transparancy 효과가있을 때 그 효과를 일으킨다. 해당 POS에 nö 추가 Point가 있습니다. 잘못된 색상의 Point가 있습니다. – AlexWien

답변

2

두 선 (수평 및 수직)의 교차점입니다.

당신이 할 수있는 일은 지금 사용하고있는 총 길이보다 몇 픽셀이나 포인트를 적게하는 것입니다. 교차하지 않고 점이 없습니다.

편집 :

또는 대신 drawling 라인

- (void)drawSquare:(CGRect)rect{ 
    //Get the CGContext from this view 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    //Draw a rectangle 
    CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor); 
    //Define a rectangle 
    CGContextAddRect(context, rect); 
    //Draw it 
    CGContextFillPath(context); 
} 
+0

+1 API 레벨에 다른 해결책이 있습니까? – Krishnan

+0

아니면 그 점을 잘릴 수 있다면? –

+0

어떻게 그럴 수 있습니까? – Krishnan

관련 문제