答案 0 :(得分: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];