jpg images in iphone and 2x images

前端 未结 5 1813
傲寒
傲寒 2021-02-04 01:33

I am working on an iphone app and targeting iOS 4.0 or later. I am trying to add an image to UIImageView, and image is in jpeg format. This i

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-04 02:20

    Write a wrapper to get the image like

    -(UIImage*) getImage:(NSString*)imageName{
    
        UIImage *image;
    
        if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00) {
    
            // RETINA DISPLAY
            NSString *jpegFile = [imageName stringByAppendingString:@"@2x.jpg"];
            image = [UIImage imageNamed:jpegFile];
        }
        else{
    
            NSString *jpegFile = [imageName stringByAppendingString:@".jpg"];
            image = [UIImage imageNamed:jpegFile];
        }
    
        return image;
    }
    

    And from your code call

    bgImageView.image                   =   getImage(@"background");
    

提交回复
热议问题