2014-10-06 94 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