UIImage and @2x

http://developer.apple.com/library/ios/#documentation/2DDrawing/Conceptual/DrawingPrintingiOS/SupportingHiResScreens/SupportingHiResScreens.html#//apple_ref/doc/uid/TP40010156-CH15-SW8

On devices with high-resolution screens, the imageNamed:imageWithContentsOfFile:, and initWithContentsOfFile: methods automatically looks for a version of the requested image with the @2x modifier in its name. It if finds one, it loads that image instead. If you do not provide a high-resolution version of a given image, the image object still loads a standard-resolution image (if one exists) and scales it during drawing.

http://www.cocoachina.com/bbs/read.php?tid-59896.html:

例如:
我只有[email protected]
當我用
UIImage *img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"1" ofType:@"png"]];
Return 一定是nil
一定要用
UIImage *img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"1@2x" ofType:@"png"]];
才會返回圖片 

------------------------------

[ NSBundle mainBundle ] pathForResource: @"[email protected]" ofType: nil ]
这里就返回nil了,可以这么做,

    NSString * path = [[ NSBundle mainBundle ] resourcePath ];
    path = [path stringByAppendingPathComponent:@"1.png"];
   UIImage *img = [UIImage imageWithContentsOfFile:path];

不明白你为啥要这么做,要提醒你的是,你的程序不能
  * 在安装了ios4.0以前地设备上跑,包括iphone4,如果安装了老系统的话
  * 在非高分屏设备,如3g, 3gs上跑(即使ios装了4.0以上)
因为你没有非高分屏的图。

猜你喜欢

转载自janedoneway.iteye.com/blog/1608170