In my iOS resource folder, I have the images:
foo~iphone.png
foo@2x~iphone.png
foo~ipad.png
foo@2x~ipad.png
I load them with:
NSString *fileName = [[NSBundle mainBundle] pathForResource:@"foo" ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:fileName];
Experimentally:
On the iPhone, filename
is /path/to/bundle/foo~iphone.png
, and on the retina iPhone, it loads the @2x
version.
On the iPad, filename
is /path/to/bundle/foo~ipad.png
, and on the retina iPad, it loads the @2x
version.
That is, it loads the image I'd hope, but pathForResource
handles the device modifier, and imageWithContentsOfFile
handles the scale modifier.
I'd like to know why. The documentation of pathForResource
says nothing about device modifiers, and the documentation of imageWithContentsOfFile
says nothing about scale modifiers.
Is there separate documentation that indicates precisely what each function does?
Best Answer
The explanation for
imageWithContentsOfFile
is in related documentation, not in theUIImage
documentation itself:I don't know which documentation explains the behavior of
pathForResource
.