显示上散射图形图像作为绘图符号在核心情节的iOS(Showing images on Scatter

2019-09-19 03:45发布

我有一个展示在我的散射图在绘图符号图像的要求。 现在我用CPTPlotSymbol绘制的图形符号。 但是,所有我能得到它是预定义的对象。 例如。 ellipsePlotSymbol,dashPlotSymbol,trianglePlotSymbol。

但我需要绘制图片代替。

你能帮我在这acheiving。 非常感谢。

Answer 1:

有尝试了一下后回答。

首先,我建立了一个自定义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 .... :)



Answer 2:

使用-symbolForScatterPlot:recordIndex:数据源方法并返回一个不同的符号高亮显示的点。 具有图像的标准矩形符号fill会做你想要什么。



Answer 3:

我看到完成这两种不同的方式,第一个是使用默认的标志之一,然后通过你的数据迭代,并添加CPTPlotSpaceAnnotation在每个点包含图像的CPTLayer。 另一个方法是创建CPTPlotSymbol的子类,并覆盖renderAsVectorInContext绘制的图像。

有可能做到这一点,我不知道一个直接的方式。



文章来源: Showing images on Scattering Graph as plot symbols in Core plot iOS