我有一个展示在我的散射图在绘图符号图像的要求。 现在我用CPTPlotSymbol绘制的图形符号。 但是,所有我能得到它是预定义的对象。 例如。 ellipsePlotSymbol,dashPlotSymbol,trianglePlotSymbol。
但我需要绘制图片代替。
你能帮我在这acheiving。 非常感谢。
我有一个展示在我的散射图在绘图符号图像的要求。 现在我用CPTPlotSymbol绘制的图形符号。 但是,所有我能得到它是预定义的对象。 例如。 ellipsePlotSymbol,dashPlotSymbol,trianglePlotSymbol。
但我需要绘制图片代替。
你能帮我在这acheiving。 非常感谢。
有尝试了一下后回答。
首先,我建立了一个自定义CPTLayer和里面所使用的图像来填补。
CustomImageForScatterPlot.h文件
#import "CPTLayer.h"
@interface CustomImageForScatterPlot : CPTLayer
{
UIImage *_image;
}
-(id)initWithImage:(UIImage *)image;
@end
CustomImageForScatterPlot.m文件
#import "CustomImageForScatterPlot.h"
#import "CPTLayer.h"
@implementation CustomImageForScatterPlot
-(void)dealloc{
[_image release];
[super dealloc];
}
-(id)initWithImage:(UIImage *)image{
CGRect f = CGRectMake(0, 0, image.size.width, image.size.height);
if (self = [super initWithFrame:f]) {
_image = [image retain];
}
return self;
}
-(void)drawInContext:(CGContextRef)ctx{
CGContextDrawImage(ctx, self.bounds, _image.CGImage);
}
@end
现在,在散点图文件,我用下面的委托方法返回图像
- (CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index
{
CustomImageForScatterPlot* layer = [[CustomImageForScatterPlot alloc] initWithImage:[UIImage imageNamed:@"dots.png"]];
layer.frame = CGRectMake(2, 0, 34, 6);
return layer;
}
享受CODING .... :)
使用-symbolForScatterPlot:recordIndex:
数据源方法并返回一个不同的符号高亮显示的点。 具有图像的标准矩形符号fill
会做你想要什么。
我看到完成这两种不同的方式,第一个是使用默认的标志之一,然后通过你的数据迭代,并添加CPTPlotSpaceAnnotation在每个点包含图像的CPTLayer。 另一个方法是创建CPTPlotSymbol的子类,并覆盖renderAsVectorInContext绘制的图像。
有可能做到这一点,我不知道一个直接的方式。