Loading @2x images failed on iPhone4?
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...
精彩评论