yuf
yuf

Reputation: 13

Using @2x files for a NonRetina iPad when @2x~ipad images exist

I have 3 images, file.png, [email protected] and file@2x~ipad.png. I want to use [email protected] on Retina iPhone and nonRetina iPad.

I want to set the images in interface builder. The iPhone works fine, where I set file.png in the xib and it loads [email protected] on Retina iPhone. But on nonRetina iPad, file@2x~ipad.png is loaded even though I specified [email protected].

Is there a way to set nonRetina iPad to default to the @2x version when a ~ipad version doesn't exist through interface builder/xibs? (I'm well aware of loading images with different extensions through code by writing custom loading code) Are there any settings or plists I can change?

I don't want to make duplicates of the same image just to be able to name them differently.

Thanks.

Upvotes: 1

Views: 1469

Answers (3)

jrtc27
jrtc27

Reputation: 8536

Use symbolic links to point myImage~iPad.png to [email protected]. Source https://stackoverflow.com/a/10223119/313875

Summary of this answer (read - someone else's answer to another question, so please go up-vote them!):

Use ln -s [email protected] myImage~ipad.png for each image. Or use a script:

#! /bin/sh

# Script to batch create symlinks that point ~ipad files to @2X files

# To run:
# Copy to the directory where the files are located
# Enter the following at the terminal prompt:
# bash create_ipad_image_links.txt

# For every @2x file we find in this directory we create a symlink

for file in *@2x.png
do
  echo "link: ${file//@2x/~ipad} to: $file" 
  ln -s $file ${file//@2x/~ipad}
done

Upvotes: 1

hypercrypt
hypercrypt

Reputation: 15376

One way of doing this without adding duplicate files is by naming the iPad version file@[email protected]. You can then set the iPad version using either [UIImage imageNamed:@"file@2x"]; or set the image to [email protected] to have file@[email protected] used on retina iPad and [email protected] on normal iPad. That way there is no duplication.

Upvotes: 1

more tension
more tension

Reputation: 3352

Try creating file~ipad.png. Non-retina iPads should look for that file first.

Upvotes: -1

Related Questions