Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
leo kamin5,550 Points
Cannot get My app to work on the retina
I am adding a background image, when I used the attributes inspector my app would work on the retina and non retina displays but when I hard-coded it It would only work on the 3.5 inch display. Here's my code:
UIImage *image = [UIImage imageNamed:@"photo"]; UIImageView *bg = [[UIImageView alloc]initWithImage:image]; [self.view insertSubview:bg atIndex:0];
Mike Baxter4,442 Points
Are you saying it won't work on a 4-inch display, or it won't work on any Retina device? Because they're two very different issues.
To work on a 4-inch display like the iPhone 5, you need to set a 4-inch Launch Screen image. Otherwise it restricts the app to only working on 3.5-inch devices.
Remember that all of your Retina images should be named something like "firstname.lastname@example.org." When you use the UIImage imageNamed method, the app checks if it's a Retina device and then proceeds to look for the image with the "@2x" in the name. Otherwise it just returns the image name.
So suppose you have an image called "photo.png", you'd need a Retina version of it called "email@example.com" also included in your app's Main Bundle, and then your code to load it would look like this:
UIImage *myImage = [UIImage imageNamed:@"photo.png"];
But that imageNamed method requires you to have "photo" stored in the app's Main Bundle (which happens when you just drag a photo into Xcode and check off the box to add it to the bundle). Maybe it's not working because it's not included?