2014-10-06 69 views
0

注释我想注释添加到我的图形通过文本和图像这样组成:核心剧情:用文字和图片

enter image description here

我已经可以显示文本(“13”在图片中),但我无法在文本下面添加图片。 我试过用CPTLayer,CPTBorderedLayer,...但他们没有按预期工作。

这里是我用来显示文本代码:

NSNumber *valueToDisplay = [NSNumber numberWithInt:13]; 
    NSString *valueToDisplayString = [formatter stringFromNumber:valueToDisplay]; 
    CPTTextLayer *textLayer = [[CPTTextLayer alloc] initWithText:valueToDisplayString style:style]; 
    self.priceAnnotation.contentLayer = textLayer; 
    self.priceAnnotation.anchorPlotPoint = [NSArray arrayWithObjects:[NSNumber numberWithFloat:7.0], [NSNumber numberWithFloat:14.0], nil]; 
    [self.graph.plotAreaFrame.plotArea addAnnotation:self.priceAnnotation]; 

如何添加下面的文本价值的形象呢?

这是代码片段我试过之一:

CPTBorderedLayer *immagine = [[CPTBorderedLayer alloc] initWithFrame:CGRectMake(0, 0, 77, 36)]; 
CPTFill *fillImage = [CPTFill fillWithImage:[CPTImage imageWithCGImage:[[UIImage imageNamed:@"sfondoStima.png"] CGImage]]]; 
     immagine.fill = fillImage; 
self.imageAnnotation.contentLayer = immagine; 
self.imageAnnotation.anchorPlotPoint = [NSArray arrayWithObjects:[NSNumber numberWithFloat:7.0], [NSNumber numberWithFloat:5.0], nil]; 
[self.graph.plotAreaFrame.plotArea addAnnotation:self.imageAnnotation]; 

不过这是结果:位图(77x36)由于某种原因而比它应该是什么大得多:

enter image description here

请给我一些帮助...我已经尝试过不同的教程/例子,我找到了,但没有一个似乎工作。

谢谢, 科拉多

+0

什么形象?数字周围的蓝色泡泡? – 2014-10-07 00:31:19

+0

将背景图像添加到CPTLayer实例? – 2014-10-07 07:17:48

+0

@Eric:确实如此。 – Corrado 2014-10-07 08:17:22

回答

1

CPTTextLayerCPTBorderedLayer一个子类。对于这样一个简单的背景,我根本不会打扰一个图像。我想尝试像这样(未经):

CPTMutableLineStyle lineStyle = [CPTMutableLineStyle lineStyle]; 
lineStyle.lineWidth = 2.0; 
lineStyle.lineColor = [CPTColor whiteColor]; 

CPTTextLayer *textLayer = [[CPTTextLayer alloc] initWithText:valueToDisplayString style:style]; 
textLayer.fill = [CPTFill fillWithColor:[CPTColor blueColor]]; 
textLayer.cornerRadius = 10.0; 
textLayer.borderLineStyle = lineStyle; 

坐落在textLayer填充控制边界线和文本之间的空间。

如果您有更复杂的需要图像的需求,请务必正确设置图像比例。 [CPTImage imageNamed:]为你做这个。

+0

它很棒!您的解决方案比使用图像好得多...谢谢! – Corrado 2014-10-08 21:20:15