我想將小工具添加到我的圖形,用戶可以點擊並拖動。我已經成功地做到這一點使用CPTPlotSpaceAnnonation(因爲我也希望它也與數據滾動)和CPTBorderedLayer。基本功能的作品,現在我想改善小部件的外觀。到目前爲止,這只是一個綠色的圓圈。更改爲CPTPlotSpaceAnnotation層形狀?
後續代碼生成圓下方,注意陰影是如何夾在層的正確,而且邊框遵循層不圓,
我怎樣才能中風圓而不是圖層?我想我可以通過使圖層的框架變大來避免裁剪。可以使用CAShapeLayer類和Core Plot註釋嗎?這將是繪製小部件的簡單方法。
// 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];
它看起來像註釋是被撫摸,它仍然是正方形。它看起來好像是註解將其子視圖限制在自己的範圍內。 – 2012-07-21 08:22:13