Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

iOS question about images

Hey guys,

I am working on an iOS app, and I have a ViewController class that has 2 corresponding .xib files, one for iPhone, and one for iPad.

I have 4 images: bg~iphone.png, bg@2x~iphone.png, bg~ipad.png and bg@2x~ipad.png. Then I add visually in Xcode one image to each .xib file. I know that programmatically we can write self.backgroundImage.image = [UIImage imageNamed:@"bg"]; and the compiler takes care to load the correct images.

My question is:

because I obviously want to set the images in Interface Builder, should I type in Attributes Inspector "bg~iphone.png and bg~ipad.png", or "bg@2x~iphone.png and bg@2x~ipad.png".

I am not sure if I specify "bg~iphone.png and bg~ipad.png", on the Retina devices, it will load the correct images (with @2x extension). It's confusing to me because of ~iphone and ~ipad suffixes, as I'm making the app universal.

Thanks in advance

2 Answers

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

@pavel if you two separate .xib files then what you are saying won't work. The device modifiers "~iphone" and "~ipad" will function if you have an image named "bg" and then it will automatically load the appropriate image based on the device. However, in your case you don't have a single .xib file and if you use the filename "bg~iphone.png" then it will look for a file named "bg~iphone*@2x*.png" for the Retina version.

Thanks Amit