gpt4 book ai didi

ios - Objective C核心图:饼图图例

转载 作者:行者123 更新时间:2023-12-01 16:58:42 26 4
gpt4 key购买 nike

在核心图中调用UILabel方法时,如何设置与饼图切片颜色相同的sliceWasSelectedAtRecordIndex:对象的颜色?我用这种方法用渐变色填充切片。

-(CPTFill *)sliceFillForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index
{
sectorColour=[[[CPTFill alloc]init]autorelease];//creating a sector color object
if (index == 0) {
//creating cptcolor
CPTColor *areaColor1 = [CPTColor colorWithComponentRed:0.0
green:0.7
blue:1.0
alpha:1.0];
CPTColor *areaColor2 = [CPTColor colorWithComponentRed:0.0
green:0.1
blue:0.2
alpha:1.0];
UIColor *color1=[UIColor colorWithRed:0.0 green:0.7 blue:1.0 alpha:1.0];
UIColor *color2=[UIColor colorWithRed:0.0 green:0.1 blue:0.2 alpha:1.0];

//filling with gradient color with CPTColor
CPTGradient *areaGradientUI = [CPTGradient gradientWithBeginningColor:(CPTColor *)color1 endingColor:(CPTColor *)color2];
sectorColour=[CPTFill fillWithGradient:areaGradientUI];
}
}

最佳答案

使用CPTGradient对象而不是CPTColor创建UIColor

CPTGradient *areaGradientUI = [CPTGradient gradientWithBeginningColor:areaColor1
endingColor:areaColor2];

您可以将 backgroundColorUILabel设置为单个 UIColor。我不确定在不制作自定义子类来绘制背景渐变的情况下如何使用渐变。

关于ios - Objective C核心图:饼图图例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9258843/

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