在核心图中调用sliceWasSelectedAtRecordIndex:
方法时,如何将UILabel
对象的颜色设置为与饼图切片颜色相同?我正在用这种方法用渐变色填充切片。
-(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
s。
CPTGradient *areaGradientUI = [CPTGradient gradientWithBeginningColor:areaColor1
endingColor:areaColor2];
您可以将UILabel
的backgroundColor
设置为单个UIColor
。我不知道如果不制作一个绘制背景渐变的自定义子类,如何使用渐变来完成这项工作。