0

我使用了核心情节。在更新(Xcode4.6 到 Xcode 5 ieios 7)之前,一切都在正常运行和显示。但更新后 Axislabels 没有显示。下面是我的代码

barChartView.frame = CGRectMake(0,30, 320, 440);
    barChartView.backgroundColor = [UIColor clearColor];
    CGRect barChartFrame=CGRectMake(0, 40, 250, 440);

    if ([UIScreen mainScreen].bounds.size.height > 500)
    {
        barChartView.frame=CGRectMake(0,50,320,460);
        barChartFrame=CGRectMake(0, 60, 250, 460);
    }

    CPTXYGraph *localBarChart = [[CPTXYGraph alloc] initWithFrame:barChartFrame];

    localBarChart.backgroundColor = [[UIColor clearColor] CGColor];


    localBarChart.plotAreaFrame.masksToBorder = NO;
    localBarChart.cornerRadius=5;

    localBarChart.paddingLeft = 70.0;
    localBarChart.paddingTop = 20.0;
    localBarChart.paddingRight = 20.0;
    localBarChart.paddingBottom = PADDING_BOTTOM;

    self.barChart= localBarChart;
    [localBarChart release];

    barChartView.hostedGraph = barChart;


    // Add plot space for horizontal bar charts

    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)barChart.defaultPlotSpace;
    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat([self.topicArray count]+1)];
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInteger(0.0) length:CPTDecimalFromInteger(100)];


    CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
    axisLineStyle.lineColor = [[CPTColor blackColor]colorWithAlphaComponent:0.5];
    axisLineStyle.lineWidth = 1.0f;

    // 2 - Get the graph's axis set
    CPTXYAxisSet *axisSet = (CPTXYAxisSet *) self.barChartView.hostedGraph.axisSet;

    static CPTTextStyle *titleStyle = nil;
    static CPTTextStyle *axisLabelTextStyle = nil;


    //CPTXYAxisSet *axisSet = (CPTXYAxisSet *)barChart.axisSet;
    CPTXYAxis *x = axisSet.xAxis;

    CPTMutableTextStyle *newStyle = [x.labelTextStyle mutableCopy];
    newStyle.color = [CPTColor redColor];
    newStyle.fontName = FONT_FAMILY_NAME;
    newStyle.fontSize = 14.0f;
    titleStyle  = newStyle;

    CPTMutableTextStyle *labelStyle = [x.labelTextStyle mutableCopy];
    labelStyle.color = [CPTColor redColor];
    newStyle.fontName = FONT_FAMILY_NAME;
    labelStyle.fontSize = 14.0f;
    axisLabelTextStyle  = labelStyle;

    x.axisLineStyle = axisLineStyle;

    x.majorTickLineStyle = nil;
    x.minorTickLineStyle = nil;
    x.majorIntervalLength = CPTDecimalFromString(@"4");
    x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
    x.titleTextStyle = titleStyle;

    x.title = @"Topics";
    // x.titleLocation = CPTDecimalFromInteger(([arrBackData count]+1)/2);
    x.titleOffset = TITLE_OFFSET;
    x.labelTextStyle = axisLabelTextStyle;

    // Define some custom labels for the data elements

    x.labelRotation = M_PI/4;
    x.labelingPolicy = CPTAxisLabelingPolicyNone;

    NSMutableArray *customTickLocations=[[NSMutableArray alloc]init];
    for (int tickLocationIndex=1; tickLocationIndex<[self.topicArray count]+1;tickLocationIndex++ )
    {

        NSString *axisLabels=[NSString stringWithFormat:@"%d",tickLocationIndex];
        [customTickLocations addObject:axisLabels];

    }

    NSMutableArray *xAxisLabels=[[NSMutableArray alloc] init];
    for(int i=1;i<[self.topicArray count]+1;i++)
    {

        NSString *axisLabels;

        axisLabels=[self.topicArray objectAtIndex:i-1];

        [xAxisLabels addObject:axisLabels];
    }

    NSUInteger labelLocation = 0;
    NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[xAxisLabels count]];
    for (NSNumber *tickLocation in customTickLocations) {
        CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText: [xAxisLabels objectAtIndex:labelLocation++] textStyle:x.labelTextStyle];
        newLabel.tickLocation = [tickLocation decimalValue];

        newLabel.offset = 1.00;
        newLabel.rotation = M_PI/2;
        [customLabels addObject:newLabel];
        [newLabel release];
    }

    [customTickLocations release];
    [xAxisLabels release];
    x.axisLabels =  [NSSet setWithArray:customLabels];

    CPTXYAxis *y = axisSet.yAxis;
    y.axisLineStyle = axisLineStyle;
    y.majorTickLineStyle = nil;
    y.minorTickLineStyle = nil;
    y.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
    y.majorGridLineStyle=nil;
    y.labelTextStyle = axisLabelTextStyle;
    y.majorIntervalLength = CPTDecimalFromString(@"10");
    y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
    y.titleTextStyle = titleStyle;
    y.title = @"No. of Question(Percentage)";

    y.titleOffset = 30.0f;


    y.titleLocation = CPTDecimalFromFloat(60.0f);

    if ([UIScreen mainScreen].bounds.size.height > 500)
    {
        y.titleLocation = CPTDecimalFromFloat(70.0f);
    }

    NSNumberFormatter *formatter = [[[NSNumberFormatter alloc] init] autorelease];
    [formatter setMaximumFractionDigits:0];
    y.labelFormatter = formatter;




    CPTBarPlot *barPlot = [[CPTBarPlot alloc] init];




    CPTMutableLineStyle *barLineStyle = [[CPTMutableLineStyle alloc] init];
    barLineStyle.lineColor = [CPTColor blackColor];
    barLineStyle.lineWidth = 0.2;

    NSString *pathToFillImage;

    pathToFillImage = [[NSBundle mainBundle] pathForResource:@"SkipBar" ofType:@"png"];
    CPTImage *fillImage = [CPTImage imageForPNGFile:pathToFillImage];
    fillImage.tiled = NO;

    CPTFill *areaGradientFill = [CPTFill fillWithImage:fillImage];
    barPlot.fill = areaGradientFill;

    barPlot.dataSource = self;
    barPlot.baseValue = CPTDecimalFromString(@"0.0");
    barPlot.barWidth=  CPTDecimalFromDouble(0.3);
    barPlot.borderColor = [[UIColor clearColor] CGColor];
    barPlot.cornerRadius = 0.0f;
    barPlot.shadowColor = nil;
    barPlot.shadowRadius = 0.0;
    barPlot.lineStyle = barLineStyle;
    barPlot.identifier = @"Bar Plot ";
    barPlot.barOffset = CPTDecimalFromDouble(0.0);
    barPlot.opacity = 0.0f;
    [barChart addPlot:barPlot toPlotSpace:plotSpace];

    [barPlot release];//#new

    CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    fadeInAnimation.duration = 5.0f;
    fadeInAnimation.removedOnCompletion = NO;
    fadeInAnimation.fillMode = kCAFillModeBoth;
    fadeInAnimation.toValue = [NSNumber numberWithFloat:1.0];
    [barPlot addAnimation:fadeInAnimation forKey:@"animateOpacity"];

    barPlot = [[CPTBarPlot alloc] init];
       barPlot.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:(0.709) green:(0.023) blue:(0.031) alpha:(1.0f)] ];
        barPlot.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:(0.756) green:(0.050) blue:(0.050) alpha:(1.0f)] ];

    NSString *pathToFillImage1;

    pathToFillImage1 = [[NSBundle mainBundle] pathForResource:@"WrongBar" ofType:@"png"];
    CPTImage *fillImage1 = [CPTImage imageForPNGFile:pathToFillImage1];
    fillImage.tiled = NO;
    CPTFill *areaGradientFill1 = [CPTFill fillWithImage:fillImage1];
    barPlot.fill = areaGradientFill1;

    barPlot.baseValue = CPTDecimalFromString(@"0.0");
    barPlot.barWidth= CPTDecimalFromDouble(0.3);
    barPlot.dataSource = self;
    barPlot.lineStyle = barLineStyle;
    barPlot.borderColor = [[UIColor clearColor] CGColor];
    barPlot.cornerRadius = 0.0f;
    barPlot.identifier = @"Bar Plot 1";
    barPlot.opacity = 0.0f;
    barPlot.shadowRadius = 0.0;
    barPlot.barOffset = CPTDecimalFromDouble(0.0);
    barPlot.shadowColor = nil;
    [barChart addPlot:barPlot toPlotSpace:plotSpace];

    [barPlot release];//#new

    fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    fadeInAnimation.duration = 5.0f;
    fadeInAnimation.removedOnCompletion = NO;
    fadeInAnimation.fillMode = kCAFillModeBoth;
    fadeInAnimation.toValue = [NSNumber numberWithFloat:1.0];
    [barPlot addAnimation:fadeInAnimation forKey:@"animateOpacity"];

    // Second bar plot
    barPlot = [[CPTBarPlot alloc] init];
     barPlot.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:(0.588) green:(0.717) blue:(0.035) alpha:(1.0f)] ];
      barPlot.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:(0.239) green:(0.588) blue:(0.031) alpha:(1.0f)] ];

    NSString *pathToFillImage2;
     pathToFillImage2 = [[NSBundle mainBundle] pathForResource:@"RightBar" ofType:@"png"];

    CPTImage *fillImage2 = [CPTImage imageForPNGFile:pathToFillImage2];
    fillImage2.tiled = NO;
    CPTFill *areaGradientFill2 = [CPTFill fillWithImage:fillImage2];
    barPlot.fill = areaGradientFill2;

    barPlot.dataSource = self;
    barPlot.baseValue = CPTDecimalFromString(@"0.0");
    barPlot.barWidth=CPTDecimalFromDouble(0.3);
    barPlot.cornerRadius = 0.0f;
    barPlot.shadowRadius = 0.0;
    barPlot.borderColor = [[UIColor clearColor] CGColor];
    barPlot.shadowColor = nil;//[[UIColor clearColor] CGColor];
    barPlot.barOffset = CPTDecimalFromDouble(0.0);
    barPlot.lineStyle = barLineStyle;
    barPlot.identifier = @"Bar Plot 2";
    barPlot.opacity = 0.0f;
    [barChart addPlot:barPlot toPlotSpace:plotSpace];
    [barLineStyle release];
    [barPlot release];//#new
4

1 回答 1

0

我解决了我的问题。这是因为UILineBreakModeWordWrap&UITextAlignment在文件 CPTTextStylePlatformSpecific.m 文件中。

1)替换UILineBreakModeWordWrapNSLineBreakByWordWrapping

2)替换UITextAlignmentNSTextAlignment

那是

[self drawInRect:rect
            withFont:theFont
       lineBreakMode:UILineBreakModeWordWrap
           alignment:(UITextAlignment)style.textAlignment];

将上面的代码替换为

[self drawInRect:rect
        withFont:theFont
   lineBreakMode:NSLineBreakByWordWrapping
       alignment:(NSTextAlignment)style.textAlignment];
于 2013-10-17T05:29:51.723 回答