2010-07-25 105 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