2012-02-13 64 views
2

如何在覈心圖中調用sliceWasSelectedAtRecordIndex:方法時如何設置與餅圖切片顏色相同的對象UILabel的顏色?我用這種方法用漸變色填充切片。Objective C核心圖:餅圖傳說

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

回答

0

使用CPTColor對象,而不是UIColor S中CPTGradient製作。

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

您可以將UILabelbackgroundColor設置爲單個UIColor。我不確定如何使用漸變而不製作繪製背景漸變的自定義子類。