开发者

Loading @2x images failed on iPhone4?

开发者 https://www.devze.com 2023-01-13 15:46 出处:网络
My code is listed below. How can I do it? UIImage *image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@\"back\"

My code is listed below. How can I do it?

UIImage *image = [UIImage imageWithContentsOfFile: 
                  [[NSBundle mainBundle] pathForResource:@"back" 
                                                  ofType:@"png"
                                             inDirectory:@"data/ui/button"]];

A great ar开发者_C百科ticle with code at: http://atastypixel.com/blog/uiimage-resolution-independence-and-the-iphone-4s-retina-display/


As the article linked mentioned, use [UIImage imageNamed:@"image.png"] and make sure your images are in the root of the bundle. I recommend against using the category in the article as Apple will make sure that imageNamed will load the proper image even if they goto a 4x image at some point in the future; the category makes assumptions about the device hardware.


Instead of imageWithContentsOfFile: method, why don't you use imageNamed: method?
I only use this for my images and they are correctly loaded for iPhone 4...

0

精彩评论

暂无评论...
验证码 换一张
取 消