Изменить внешний вид заголовка круговой диаграммы основного графика
Я хотел бы использовать простой черный фон для своей круговой диаграммы, которую я генерирую с помощью 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];
}
Большое спасибо заранее за любую помощь / совет / ссылки, предлагаемые...
1 ответ
Решение
Я нашел ответ, который все время смотрел мне в лицо, в примере кода Core Plot...
Для всех, кто сталкивается с этим вопросом, вот ответ:
CPTMutableTextStyle *whiteText = [CPTMutableTextStyle textStyle];
whiteText.color = [CPTColor whiteColor];
graph.titleTextStyle = whiteText;
graph.title = @"Your Title Here...";