2011-10-21 35 views
1

我又增加了標籤餅圖這樣 - (CPTLayer *)dataLabelForPlot:(CPTPlot *)情節recordIndex:(NSUInteger)指數 {我如何包裝文字添加到情節在iPhone SDK中使用的核心情節庫

CPTTextLayer *newLayer = nil; 
UIFont *theFont; 

static CPTMutableTextStyle *whiteText = nil; 

if (!whiteText) 
{ 
    whiteText = [[CPTMutableTextStyle alloc] init]; 
    whiteText.color = [CPTColor blackColor]; 
    whiteText.textAlignment = CPTTextAlignmentCenter; 
    whiteText.fontName = @"Helvetica-Bold"; 
    whiteText.fontSize = 10.0f; 
    theFont = [UIFont fontWithName:whiteText.fontName size:whiteText.fontSize]; 


} 
if ([plot isKindOfClass:[CPTPieChart class]]) 
{ 
    newLayer.delegate = self; 
    newLayer = [[[CPTTextLayer alloc] initWithText:[NSString stringWithFormat:@"%@", [pieChartData2 objectAtIndex:index]] style:whiteText] autorelease]; 
     } 

return newLayer; 
    } 

我想這裏是 (1)我想換行是太長的文字。 (2)我想顯示Slice標題和它的值。 (3)我需要畫一條線來標題和切片。 請任何人幫助我。

在此先感謝

回答

1
  1. 您可以在文本中插入換行符(「\ n」)換到下一行。 Core Plot不會自動包裝任何文本。

  2. 這是一種數據源方法 - 它應該可以訪問數據值和標題。使用兩者來構建標籤字符串。

  3. 尚未支持爲標籤繪製線條。您可以製作CPTTextLayer的自定義子類,以便除了文本之外還繪製線條,並使用該子類代替庫存CPTTextLayer製作標籤。