Note that there are some explanatory texts on larger screens.

plurals
  1. POImage resources for iOS
    primarykey
    data
    text
    <p>I'm probably missing something obvious here, yet I've been unable to solve the following problem: </p> <p>I have a project with image resources for both normal and retina screens, like <em>someimage.png</em> and <em>someimage@2x.png</em>, which are stored in a separate bundle. When I build the project, Xcode automatically packs them into a single multipage tiff (<code>imageName.tiff</code>), I've checked it in finder - it is actually multipage tiff with both images. However, here comes a problem: I struggle to load appropriate resource.</p> <p>What I do is:</p> <pre><code> NSString * imageName = ... ; NSLog(@"imageName: %@", imageName); UIImage * someImage = [UIImage imageNamed: imageName]; </code></pre> <p>Also I fave auxiliary method, which returns bundle with resources:</p> <pre><code> +(NSBundle *) resourcesBundle { NSBundle *bundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"MyResourcesBundle" withExtension:@"bundle"]]; return bundle; } </code></pre> <p>I've tried following for <code>imageName</code>:</p> <pre><code>imageName = [[AuxClass resourcesBundle] pathForResource:@"someimage" ofType:@"png"]; </code></pre> <p>in this case i have <code>null</code> for <code>imageName</code>.</p> <pre><code>imageName = [[AuxClass resourcesBundle] pathForResource:@"someimage" ofType:@"tiff"]; </code></pre> <p>in this case actuall image path is returned, however it only works if I use <code>imageWithContentsOfFile</code> instead of <code>imageNamed</code>, and it doesn't take appropriate resource: it loads resource for retina despite the type of screen.</p> <p>If I ommit filetype (as I did before adding <code>@2x</code> resources, and it worked ok, and was the first thing I tried and was sure it would work)</p> <pre><code>imageName = [NSString stringWithFormat: @"%@/%@", @"MyResourcesBundle.bundle"", @"someimage" ]; </code></pre> <p>nothing get's loaded.</p> <p>Adding ".tiff" extension have the same effect as <code>pathForResource:</code> - resource for retina is loaded, disregarding resource for non-retina screen.</p> <p>So what am I missing? What's the correct way of loading images?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload