我想将小工具添加到我的图形,用户可以点击并拖动。我已经成功地做到这一点使用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