gpt4 book ai didi

iphone - 更改 Core Plot 饼图标题的外观

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:23:54 25 4
gpt4 key购买 nike

我想对使用 Core Plot 生成的饼图使用纯黑色背景。我的图表呈现得很好,但标题是默认的 blackColor,这在黑色背景上很难看清。我知道它正在显示,因为当我更改主题时,我可以看到它是黑色的。谁能告诉我如何像更改数据标签那样更改文本颜色?

这是我的代码片段...

    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];
}

非常感谢您提供的任何帮助/建议/链接...

最佳答案

我在 Core Plot 示例代码中找到了一直盯着我看的答案...

对于其他遇到这个问题的人来说,这里就是答案:

CPTMutableTextStyle *whiteText = [CPTMutableTextStyle textStyle];
whiteText.color = [CPTColor whiteColor];
graph.titleTextStyle = whiteText;
graph.title = @"Your Title Here...";

关于iphone - 更改 Core Plot 饼图标题的外观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9763664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com