0

How to Full screen Specify Images for 4-inch iOS devices. The 568@2x will only work for Default image Any Approaches will be use full. Please share some code snippet.

4

2 回答 2

2

在这种情况下,您需要为 UIImage 编写一个类别方法,并在所有需要全屏图像的地方使用该方法,并提及一个

我的命名约定:

  • 普通图片:img.png

  • 视网膜图像:img@2x.png

  • 4寸屏幕:img-4@2x.png

  • HEIGHT 是屏幕高度

代码:

   UIImageView *bgImg = [UIImageView alloc] initWithImage:[UIImage imageNamed5:@"img.png"];  

分类实现:

+(UIImage *) imageNamed5:(NSString *) imgName
 {

    NSArray *paths =[imgName componentsSeparatedByString:@"."];
    UIImage *img =nil;
    if(paths.count == 2){
        NSString *imgNme =[paths objectAtIndex:0];
        NSString *ext = [paths objectAtIndex:1];
        NSString *imgPath;
        if(HEIGHT == 568)
        {
            imgPath = [NSString stringWithFormat:@"%@%@%@",imgNme,@"-4@2x.",ext];
        }
        else
        {
            imgPath = imgName;
        }
        img = [UIImage imageNamed:imgPath];
    }
    if(img == nil){
        img = [UIImage imageNamed:imgName];
    }
    return img;
}
于 2013-10-01T06:42:08.520 回答
0

我用这种方式

Appdelegate *delegate = [[UIApplication sharedApplication]delegate];
    //check the height of window
   if (delegate.window.frame.size.height == 568)
   {
       //use image_568@2x
   }else{
       //use normal image
   }
于 2013-10-01T06:46:01.050 回答