2010-07-25 141 views

回答

3

我能三個標籤添加到圖形像這樣的頂部:

CPTextStyle *textStyle1 = [CPTextStyle textStyle]; 
textStyle1.color = [CPColor blueColor]; 
textStyle1.fontSize = 14; 
CPTextStyle *textStyle2 = [CPTextStyle textStyle]; 
textStyle2.color = [CPColor greenColor]; 
textStyle2.fontSize = 14; 
CPTextStyle *textStyle3 = [CPTextStyle textStyle]; 
textStyle3.color = [CPColor redColor]; 
textStyle3.fontSize = 14; 

CPTextLayer *layer1 = [[[CPTextLayer alloc] initWithText:[NSString stringWithFormat:@"text1"]] autorelease]; 
CPTextLayer *layer2 = [[[CPTextLayer alloc] initWithText:[NSString stringWithFormat:@"text2"]] autorelease]; 
CPTextLayer *layer3 = [[[CPTextLayer alloc] initWithText:[NSString stringWithFormat:@"text3"]] autorelease]; 
layer1.bounds = CGRectMake(-75,2,20,10); 
layer1.textStyle = textStyle1; 
layer2.bounds = CGRectMake(-130,2, 20,10); 
layer2.textStyle = textStyle2; 
layer3.bounds = CGRectMake(-190,2, 20,10); 
layer3.textStyle = textStyle3; 

CPLayerHostingView * newView = [[CPLayerHostingView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]]; 
newView.hostedLayer = graph; 
NSInteger count = [graph.sublayers count]; 
[graph insertSublayer:layer1 atIndex: count + 1]; 
[graph insertSublayer:layer2 atIndex: count + 2]; 
[graph insertSublayer:layer3 atIndex: count + 3]; 
self.view = newView; 
[newView release]; 
+0

謝謝您的回答它真的幫助我,但唯一的問題是,當我試圖設置顏色和字體soze ,它給我一個錯誤「錯誤:對象無法設置 - 只讀屬性或沒有設置找到」 我必須做點什麼 – Pooja 2011-05-18 08:44:59

+0

我不得不使用CPMutableTextStyle而不是CPTextStyle來使它工作。 – 2011-07-19 17:07:43

+0

看起來圖書館的名稱已更改。如果海報更新了代碼以將CP更改爲CPT,那將會很棒。 – 2011-08-03 21:21:15