2012-07-21 3 views
1

사용자가 클릭하여 끌 수있는 그래프에 위젯을 추가하고 싶습니다. CPTPlotSpaceAnnonation을 사용하여이 작업을 수행했습니다. 왜냐하면 CPTlordSpaceAnnonation은 데이터로 스크롤하기를 원하기 때문입니다. CPTBorderedLayer. 기본 기능이 작동하고 이제 위젯의 모양을 개선하고 싶습니다. 지금까지는 단지 녹색 원이었습니다.CPTPlotSpaceAnnotation의 레이어 모양을 변경 하시겠습니까?

는 다음과 코드는 아래의 원을 생성하는 그림자 레이어의 RECT 클리핑하는 방법을주의하고 경계 레이어가 아닌 원, 어떻게 내가 뇌졸중 원

enter image description here

을 다음과 레이어가 아닌가요? 레이어의 프레임을 크게하여 클리핑을 피할 수 있다고 생각합니다. Core Plot 주석과 함께 CAShapeLayer 클래스를 사용할 수 있습니까? 이것은 위젯을 그리는 쉬운 방법 일 것입니다.

// Add a circular annotation to graph with fill and shadow 
annotation = [[CPTPlotSpaceAnnotation alloc] 
        initWithPlotSpace:graph.defaultPlotSpace 
        anchorPlotPoint:anchorPoint]; 

// Choosing line styles and fill for the widget 
NSRect frame = NSMakeRect(0, 0, 50.0, 50.0); 
CPTBorderedLayer *borderedLayer = [[CPTBorderedLayer alloc] initWithFrame:frame]; 

// Circular shape with green fill 
CGPathRef outerPath = CGPathCreateWithEllipseInRect(frame, NULL); 
borderedLayer.outerBorderPath = outerPath; 
CPTFill *fill = [CPTFill fillWithColor:[CPTColor greenColor]]; 
borderedLayer.fill = fill; 

// Basic shadow 
CPTMutableShadow *shadow = [CPTMutableShadow shadow]; 
shadow.shadowOffset = CGSizeMake(0.0, 0.0); 
shadow.shadowBlurRadius = 6.0; 
shadow.shadowColor = [[CPTColor blackColor] colorWithAlphaComponent:1.0]; 
borderedLayer.shadow = shadow; 

// Add to graph 
annotation.contentLayer = borderedLayer; 
annotation.contentLayer.opacity = 1.0; 
[graph addAnnotation:annotation]; 
+0

주석이 쓰다듬어지고 여전히 정사각형 인 것처럼 보입니다. 또한 주석이 하위보기를 자체 범위로 클리핑하는 것처럼 보입니다. –

답변

0

레이어의 경계 경로를 설정하지 마십시오. 대신 cornerRadius을 프레임 너비의 절반으로 설정하면됩니다.

borderedLayer.cornerRadius = frame.size.width * 0.5; 
+0

나는 그것을 생각하지 않았다, 고마워. 어둠이 없으면 이것이 최고의 해결책입니다. 그러나 그림자와 함께 클립과 프레임, 위와 같습니다. –

+0

CorePlot 주석 코드에서 CALayer를 사용하는 경우 CAShapeLayer가 필요하기 때문에 CorePlot을 사용하여이 작업을 수행 할 수 있다고 생각하지 않습니다. 필자는 CAShapeLayer와 함께 작동하는 사용자 지정 주석을 구현하고 구현하기로 결정했습니다. –

관련 문제