在iPhone6中丢失的piechat切片适用于iphone5

时间:2017-03-23 06:13:33

标签: ios objective-c ios10 pie-chart iphone-6

我正在使用BNPieChart。 iPhone6s(iOS 10.2.1)中的Piechart切片丢失了,但相同的代码适用于iPhone5s(iOS 10.2.1)和iPhone5s(iOS 10.2.1)。

这是我的代码:

- (void)viewDidAppear:(BOOL)animated {

    CGRect pieFrame = CGRectMake(30, 78, 240, 240);
    self.chart = [[BNPieChart alloc] initWithFrame:pieFrame];

    BNColor *emergencyColor = [BNColor colorWithRed:142.0/255.0 green:1.0/255.0 blue:32.0/255.0];
    BNColor *urgentColor = [BNColor colorWithRed:231.0/255.0 green:133.0/255.0 blue:8.0/255.0];
    BNColor *nonUrgentColor = [BNColor colorWithRed:97.0/255.0 green:147.0/255.0 blue:3.0/255.0];

    self.chart.colors = [NSArray arrayWithObjects:emergencyColor,urgentColor,nonUrgentColor, nil];

    [self.chart addSlicePortion:emergencyCount/totalCount withName:[NSString stringWithFormat:@"%.1f%%",(emergencyCount/totalCount)*100]];
    [self.chart addSlicePortion:urgentCount/totalCount withName:[NSString stringWithFormat:@"%.1f%%",(urgentCount/totalCount)*100]];
    [self.chart addSlicePortion:nonUrgentCount/totalCount withName:[NSString stringWithFormat:@"%.1f%%",(nonUrgentCount/totalCount)*100]];

    [self.view addSubview:self.chart];
}

在iphone6上它唯一的显示渐变深灰色圆圈,请看图片: enter image description here

但它适用于iPhone5(iOS 10.2.1)

enter image description here

1 个答案:

答案 0 :(得分:0)

实际上,需要在BNPieChart类本身进行更改。 CGFloatfloat*之间存在不兼容性 将BNPieChart.m中的以下代码行替换为以下代码:

//  CGFloat red, green, blue;
//  [self getRGBForIndex:index red:&red green:&green blue:&blue];

CGFloat red, green, blue;
BNColor *color = [colors objectAtIndex:(index % [colors count])];
red = color.red;
green = color.green;
blue = color.blue;

观看viewDidAppear以获得结果。如果有人像我一样实施了BNPieChart,那就行得很好。