2013-02-01 113 views

回答

0

UIKit支持@2x设备修改器的规范,以便通过imageNamed方法选择图像的视网膜启用版本。

这将允许管理相同图像的非视网膜和视网膜版本。不幸的是,没有规定自动处理iPhone5版本的图像(Default.png除外)。你必须自己做。

或者,你可以使用this category能够使用[email protected]设备扩展您的具体iPhone5的图像:

+ (UIImage*)imageNamedForDevice:(NSString*)name { 

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
{ 
if (([UIScreen mainScreen].bounds.size.height * [UIScreen mainScreen].scale) >= 1136.0f) 
{ 
    //Check if is there a path extension or not 
    if (name.pathExtension.length) { 
    name = [name stringByReplacingOccurrencesOfString: [NSString stringWithFormat:@".%@", name.pathExtension] 
              withString: [NSString stringWithFormat:@"[email protected]%@", name.pathExtension ] ]; 

    } else { 
    name = [name stringByAppendingString:@"[email protected]"]; 
    } 

    //load the image e.g from disk or cache 
    UIImage *image = [UIImage imageNamed: name ]; 
    if (image) { 
    //strange Bug in iOS, the image name have a "@2x" but the scale isn't 2.0f 
    return [UIImage imageWithCGImage: image.CGImage scale:2.0f orientation:image.imageOrientation]; 
    } 

} 
} 

return [UIImage imageNamed: name ]; 

} 
0

这是做这件事的横盘方式,但也非常快:

int screenHeight = self.view.bounds.size.height; 
if (screenHeight<500) { 
    //Show the UIImage for iPhone 4. 
} 
else { 
    //Show the UIImage for iPhone 5. 
} 
+0

为什么只是'500'? – holex

+0

iPhone 4屏幕高480。 iPhone 5的屏幕是568.你可以选择两个之间的任何数字--481,568,只要它们落在它的两侧。 500只是最简单的。 –

+0

它听起来不太专业,为什么不使用'if screenHeight <(arc4random()%88 + 480){...}'公式?这也没有意义。 – holex

相关问题