Objective C核心图:饼图图例

时间:2012-02-13 10:23:12

标签: ios core-plot

在核心图中调用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];
    }
}

1 个答案:

答案 0 :(得分:0)

使用CPTGradient对象制作CPTColor,而不是UIColor

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

您可以将backgroundColor的{​​{1}}设置为单个UILabel。我不确定如何使用渐变来实现它,而不会创建绘制背景渐变的自定义子类。