Iphone 在coreplot图中的标签后面和绘图前面放置一个图像
如何在图形中获得标签后面的图像。我成功地在图表前面放置了一个图像,其中包括:Iphone 在coreplot图中的标签后面和绘图前面放置一个图像,iphone,graph,label,core-plot,layer,Iphone,Graph,Label,Core Plot,Layer,如何在图形中获得标签后面的图像。我成功地在图表前面放置了一个图像,其中包括: CPTPlotSpaceAnnotation *imageAnnotation; CGRect imageRect = CGRectMake(0, 0 , 480, 320); CPTBorderedLayer * ImageLayer = [[CPTBorderedLayer alloc] initWithFrame:imageRect]; ImageLayer.fill = [CPTF
CPTPlotSpaceAnnotation *imageAnnotation;
CGRect imageRect = CGRectMake(0, 0 , 480, 320);
CPTBorderedLayer * ImageLayer = [[CPTBorderedLayer alloc] initWithFrame:imageRect];
ImageLayer.fill = [CPTFill fillWithImage:[CPTImage imageWithCGImage:[[UIImage imageNamed:@"Overlay_3_digits.png"] CGImage]]];
imageAnnotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:plotSpace anchorPlotPoint:nil];
imageAnnotation.contentLayer = ImageLayer;
[graph addAnnotation:imageAnnotation];
[graph addSublayer:ImageLayer];
[newImagelLayer release];
[imageAnnotation release];
使用[graph insertSubLayer:ImageLayer Lower:y]添加图像;不起作用,这也会将图像放在图形和标签的前面。希望有人能帮我
编辑:
我添加了来自模拟器的屏幕截图。这三个黑色矩形必须位于绘图的前面和标签的后面。标签将更容易阅读
我还通过将AxisLabel放在第一个索引处,编辑了图形中的图层层次结构:
NSArray *chartLayers = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:CPTGraphLayerTypeAxisLabels],
[NSNumber numberWithInt:CPTGraphLayerTypePlots],
[NSNumber numberWithInt:CPTGraphLayerTypeMajorGridLines],
[NSNumber numberWithInt:CPTGraphLayerTypeMinorGridLines],
[NSNumber numberWithInt:CPTGraphLayerTypeAxisLines],
[NSNumber numberWithInt:CPTGraphLayerTypeAxisTitles],
nil];
graph.topDownLayerOrder = chartLayers;
我还发现了一种更好的方法,可以将我的图像放入图表中。我通过一个新的主机层实现了这一点:
CPTAnnotationHostLayer *newHostLayer = [[CPTAnnotationHostLayer alloc]
initWithFrame:CGRectMake(0, 0, 480, 220)];
UIImage * annotationBG = [UIImage imageNamed:@"Overlay_3_digits.png"];
newHostLayer.backgroundColor = [UIColor colorWithPatternImage:annotationBG].CGColor;
你知道如何将三个黑色三角形图像放在标签后面和绘图前面吗?使用
-addAnnotation:
方法更新图层树;您应该删除对-addSublayer:
的调用
是否希望图像完全填充图形后面的背景?如果是这样,只需在图形上设置fill
,而不是进行注释
graph.fill = [CPTFill fillWithImage:[CPTImage imageWithCGImage:[[UIImage imageNamed:@"Overlay_3_digits.png"] CGImage]]];
要将框放在每个标签后面,可以使用自定义标签。构建一个
CPTBorderedLayer
,方法与对注释所做的相同。添加带有标签文本的CPTTextLayer
,作为边界层的子层。使边界层成为自定义标签的contentLayer
。这将消除更改topDownLayerOrder
的需要。我希望图像放置在图形的前面和axislabels的后面我更改了graph.topDownLayerOrder的层次结构,以便axislabels位于顶部我成功地添加了一个图像->CptAnotationHostLayer*newHostLayer=[[CptAnotationHostLayer alloc]initWithFrame:CGRectMake(0,0480220)];UIImage*annotationBG=[UIImage ImageName:@“Rechts.png”];newHostLayer.backgroundColor=[UIColor-WithPatternImage:annotationBG].CGColor;最后一行:[graph insertSublayer:newHostLayer下方:y];将我的图像放置在标签顶部有什么想法吗?我可以如何更改层次结构,使新创建的hostLayer位于标签的后面和绘图的前面?也许删除y轴并在新的子层中再次设置它,这使我能够将新的主机层设置为axislayer下面的子层?我的感觉是,您已经过多地考虑了这一点,并使它变得更加复杂,但我无法想象您正在努力做什么,以阐明解决方案。你能发布一张你想要达到的效果的模型图片吗?我编辑了我的答案。你有什么想法吗Eric,我猜你是coreplot专业人士;)