가운데에서 삼각형을 잘라 반투명의 검은 색 사각형을 그리려고합니다.QuartzCore - 다각형에 둥근 모서리 추가하기
아래 코드와 완벽하게 작동합니다. 그러나 삼각형의 모서리를 둥글게하고 싶습니다.
뇌졸중을 위해 CGContextSetLineCap을 설정하고 quartz로 내 경로를 만들고 CGContextAddArcToPoint를 사용하여 둥근 모서리를 추가하는 데 몇 가지 다른 방법을 시도했지만 아무 것도 작동하지 못했습니다.
앞서 언급했듯이 아래 코드는 삼각형 컷 아웃에 사용됩니다. 삼각형의 모서리를 어떻게 둥글게 할 수 있습니까?
CGContextRef context = UIGraphicsGetCurrentContext();
CGPoint position = CGPointMake(rect.size.width/2, rect.size.height * .7);
CGSize size = CGSizeMake(rect.size.width*.8, rect.size.height*.5);
CGFloat firstPointX = (position.x - (size.width/2));
CGFloat firstPointY = (position.y - (size.height));
CGPoint firstPoint = CGPointMake(firstPointX, firstPointY);
CGFloat secondPointX = position.x + (size.width/2);
CGFloat secondPointY = position.y - (size.height);
CGPoint secondPoint = CGPointMake(secondPointX, secondPointY);
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:position];
[path addLineToPoint:firstPoint];
[path moveToPoint:firstPoint];
[path addLineToPoint:secondPoint];
[path addLineToPoint:position];
[path closePath];
CGContextAddRect(context, rect);
CGContextAddPath(context, path.CGPath);
CGContextEOClip(context);
UIColor *translucentColor = [UIColor colorWithWhite:0 alpha:0.5];
CGContextSetFillColorWithColor(context, translucentColor.CGColor);
CGContextFillRect(context, rect);
UIGraphicsEndImageContext();
편집 : 다음은 내가 달성하려고 시도하는 것의 예입니다.
OK - 시도했기 때문에 이전 답변이 삭제되었으며 클리핑과 함께 작동하지 않을 수 있습니다. 경로를 선을 그으면 둥근 선이 잘 작동합니다. 그리고 그것은 지금 4am입니다. 나는 내일 또 다른 시도를 할 것이다. –
CGContextAddArc를 사용해 보셨습니까? – badweasel