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 trialKal K
13,332 PointsSetting Background Images for Various Screen Sizes Error
I have tried all of the things recommended by Ben in the video after his app did not work either. i have found that app at the size of 3.5 inches works but at 4 inches i just have a white background. Can someone please help me? Perhaps you can help Ben Jakuben? Here is the code i had to display the bigger picture
- (void)viewDidLoad {
[super viewDidLoad];
if ([UIScreen mainScreen].bounds.size.height == 568) {
self.backgroundImageView.image = [UIImage imageNamed:@"loginBackground-568h"];
}
}
8 Answers
Thomas McCracken
13,591 PointsOk, I couldn't get the 4" image to come in so I just stretched the 3.5" image to fill the screen as a quick fix:
if ([UIScreen mainScreen].bounds.size.height == 568) { self.backgroundImageView.frame = self.view.frame;
self.backgroundImageView.image = [UIImage imageNamed:@"loginBackground"];
}
Hopefully this is just a work-around until someone...(ahem, Ben)...solves this mystery.
Charlie O'Shea
18,737 PointsNo luck for me either. Followed all fixes in video to no avail. Also tried reuploading the 568 image without the hyphen incase that was interfering but didn't work. Going with Thomas McCrackens quick fix for now but would be great to learn how to do this properly Ben. I'm in XCode 6 by the way.
Oh and another thing which I couldn't do in the video was making the Storyboard view controllers toggle between 3.5 and 4 inches as the button seems to have vanished in Xcode 6. I could use the assistant editor preview to see other screen size, but can't work out how I can stretch the image to 4inch size as per the video.
Daniel Monday
140 PointsI'm also having the same issue, did you find a way around this?
Thanks
David Kusek
2,880 PointsAlso stuck here
Christopher Santos
Courses Plus Student 10,697 PointsI was able to display the background by using @"loginBackground" for the filename instead of @"loginBackground-568h" But that is the file name of the lowest res image. Maybe xcode doesn't like the special characters in the file names of the higher res images.
Thomas McCracken
13,591 PointsI'm having the same issue too. The "loginBackground" image works fine just like Christopher Santos said but not "loginBackground-568h". Really wish I could figure out a solution...I'm going to try changing the name to exclude the dash and see what happens.
Gareth Holton
258 Pointsthe way i found to to solve the problem was to simply resize the image which fortunately doesn't seem to blur or pixelate the image simply add
loginBackground.frame = CGRectMake(0, 0, 320,568);
you could also expand on this and create integers in the if statements that then equal the width and height of the current device and pass them through the parameters of the CGrect hope this helps !
Pablo Alfaro
Courses Plus Student 6,923 PointsA workaround that worked for me was to add constraints to the UIImageView. I pinned all four sides at 0 and have tested it on iPhone 4 - iPhone 6s plus and it seems to work fine without the images getting pixelated or distorted.