0

デバイスにバグがあります。IOSシミュレーターではすべて良好です。デバイスにテキストレイヤーを正しく表示したい。

デバイスからのこの写真。 ここに画像の説明を入力

IOSシミュレーターからのこの写真 ここに画像の説明を入力

グラフにテキストレイヤーを追加するコード

-(void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)index
{

    if ( symbolTextAnnotation ) {
        [self.graph.plotAreaFrame.plotArea removeAnnotation:symbolTextAnnotation];
        symbolTextAnnotation = nil;
    }

    CPTMutableTextStyle *hitAnnotationTextStyle = [CPTMutableTextStyle textStyle];
    hitAnnotationTextStyle.color    = [CPTColor whiteColor];
    hitAnnotationTextStyle.fontSize = 14.0f;
    hitAnnotationTextStyle.fontName = @"Helvetica";

    NSNumber *x          = [[self.plotDataFact objectAtIndex:index] valueForKey:@"x"];
    NSNumber *y          = [[self.plotDataFact objectAtIndex:index] valueForKey:@"y"];
    NSArray *anchorPoint = [NSArray arrayWithObjects:x, y, nil];

    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init] ;
    [formatter setMaximumFractionDigits:2];
    NSString *yString = [formatter stringFromNumber:[NSNumber numberWithFloat:[y floatValue] * graphYStep]];

    CPTTextLayer *textLayer = [[CPTTextLayer alloc] initWithText:yString style:hitAnnotationTextStyle];
    symbolTextAnnotation              = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:self.graph.defaultPlotSpace anchorPlotPoint:anchorPoint];
    symbolTextAnnotation.contentLayer = textLayer;

    textLayer.borderColor = [[UIColor whiteColor] CGColor];
    textLayer.borderWidth = 0.5;
    textLayer.cornerRadius = 4;
    textLayer.backgroundColor = [[UIColor colorWithRed:85.0/255.0 green:85.0/255.0 blue:85.0/255.0 alpha:1.0] CGColor];

    symbolTextAnnotation.displacement = CGPointMake(0.0f, 20.0f);
    [self.graph.plotAreaFrame.plotArea addAnnotation:symbolTextAnnotation];

}
4

0 に答える 0