3
我想使用簡單的黑色背景添加到我使用Core Plot生成的餅圖中。我有很好的圖表渲染,但標題是在黑色背景上很難看到的默認黑色。我知道這是顯示,因爲當我改變主題時,我可以看到它黑色。任何人都可以告訴我如何改變文字顏色,就像我對數據標籤做的一樣?更改Core Plot餅圖標題的外觀
這裏是我的代碼片段...
graph = [[CPTXYGraph alloc] initWithFrame:self.view.bounds];
CPTGraphHostingView *hostingView = (CPTGraphHostingView*)self.view;
hostingView.hostedGraph = graph;
CPTPieChart *pieChart = [[CPTPieChart alloc] init];
pieChart.dataSource = self;
pieChart.pieRadius = 80.0;
pieChart.identifier = @"PieChart1";
pieChart.startAngle = M_PI_4;
pieChart.sliceDirection = CPTPieDirectionCounterClockwise;
[graph addPlot:pieChart];
graph.title = @"Proportion of Sessions per Sport";
}
-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index {
static CPTMutableTextStyle *whiteText = nil;
if (!whiteText) {
whiteText = [[CPTMutableTextStyle alloc] init];
whiteText.color = [CPTColor whiteColor];
}
CPTLayer *layer = [[CPTLayer alloc] initWithFrame:CGRectMake(50, 50, 100, 20)];
CPTTextLayer *newLayer = nil;
newLayer = [[CPTTextLayer alloc] initWithText:[NSString stringWithFormat:@"%@", [pieLabels objectAtIndex:index]] style:whiteText];
[layer addSublayer:newLayer];
return newLayer;
}
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
return [self.pieData count];
}
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {
return [self.pieData objectAtIndex:index];
}
-(NSString *)legendTitleForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index {
return [NSString stringWithFormat:@"Pie Slice %u", index];
}
提前提供的任何幫助/諮詢/鏈接感謝...