Core Plot 1.0 Retina images not displayed correctly

别等时光非礼了梦想. 提交于 2019-12-11 00:06:45

问题


I am just about done with my App and have added some great things with core plot and the help of their dedicated staff. My question pertains to using images with the retina display. I have an annotation that is a picture of a speech bubble. When I run the App in the simulator, it displays fine for regular resolution, but when I switch to retina, the image is cropped. See pictures below. I have a .png that I called Bubble, and I added another that is called Bubble@2x, which is twice the size, I thought this was what I needed to do. That did not work. So I have tried to set the view.contentScale, see below code. But nothing seems to work. Anyone have any ideas what I am forgetting to do? Thanks once again.

{
    //first annotation
    NSValue *value = [self.myData objectAtIndex:index];
    CGPoint point = [value CGPointValue];
    NSString *number1 = [NSString stringWithFormat:@"(%.2f, ", point.x];
    NSString *number2 = [NSString stringWithFormat:@"%.2f)", point.y];
    NSNumber *x = [NSNumber numberWithFloat:point.x];
    NSNumber *y = [NSNumber numberWithFloat:point.y];    
    NSArray *anchorPoint = [NSArray arrayWithObjects: x, y, nil];
    NSString *final = [number1 stringByAppendingString:number2];

    //second annotation        
    UIImage *bubble = [UIImage imageNamed:@"Bubble.png"];
    CPTImage *fillimage = [CPTImage imageWithCGImage:bubble.CGImage];
    CPTBorderedLayer *imageLayer = [[CPTBorderedLayer alloc] init];
    //imageLayer.contentsScale = [[UIScreen mainScreen] scale]; //tried this
    imageLayer.frame = CGRectMake(0, 0, 150, 80);
    //imageLayer.contentsScale = 2.0f;  //and this

    imageLayer.fill = [CPTFill fillWithImage:fillimage];

    CPTTextLayer *textLayer = [[CPTTextLayer alloc] initWithText:final style:annotationTextStyle];
    _annotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:graph.defaultPlotSpace anchorPlotPoint:anchorPoint];        
    _annotation.contentLayer = textLayer;        
    _annotation.displacement = CGPointMake(90.0f, 5.0f);
    _annotation.rotation = M_PI * .03f;

    _picAnnotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:graph.defaultPlotSpace anchorPlotPoint:anchorPoint];
    _picAnnotation.contentLayer = imageLayer;
    _picAnnotation.displacement = CGPointMake(75.0f, 5.0f);

}

after that code, I then placed both of the annotations. As you can see one works, the other doesn't.


回答1:


You should pass the image scale when creating a CPTImage if you need to support Retina images.

CPTImage *fillimage = [CPTImage imageWithCGImage:bubble.CGImage
                                           scale:bubble.scale];


来源:https://stackoverflow.com/questions/12494324/core-plot-1-0-retina-images-not-displayed-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!