Objective c 核心图:文本和图像注释
我想在我的图表中添加一个注释,由文本和图像组成,如下所示: 我已经可以显示文本(图片中的“13”),但无法在文本下方添加图像。 我试过使用CPTLayer、CPTBorderedLayer,…,但没有一个像预期的那样工作 下面是我用来显示文本的代码:Objective c 核心图:文本和图像注释,objective-c,annotations,core-plot,Objective C,Annotations,Core Plot,我想在我的图表中添加一个注释,由文本和图像组成,如下所示: 我已经可以显示文本(图片中的“13”),但无法在文本下方添加图像。 我试过使用CPTLayer、CPTBorderedLayer,…,但没有一个像预期的那样工作 下面是我用来显示文本的代码: NSNumber *valueToDisplay = [NSNumber numberWithInt:13]; NSString *valueToDisplayString = [formatter stringFromNumbe
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)由于某种原因比它应该的大得多:
请给我一些帮助。。。我已经尝试了我找到的不同的教程/示例,但它们似乎都不起作用
谢谢,
Corrado是CPTBorderedLayer的一个子类。对于这样一个简单的背景,我根本不需要图像。我会尝试这样(未经测试): 在
textLayer
上设置填充,以控制边框线和文本之间的间距
如果您有更复杂的需要图像,请确保正确设置图像比例<代码>[CPTImage IMAGENAME:::为您执行此操作。什么图像?数字周围的蓝色气泡?向CPTLayer实例添加背景图像?@Eric:是的,没错。@Mike:我尝试过使用CPTLayer,但没有成功。你有代码示例吗?
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;