Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I manage background images for the iPhone 5?

Some of my apps use custom images as the background. What is the proper way to check the screen size to place the proper image?

Should it be something like this in viewDidLoad:

if ([UIScreen mainScreen] == 2.0)
{
     UIImage * backgroundImage = [UIImage imageNamed:@"[email protected]"];
     backgroundImageView = [[UIImageView alloc] initWithImage:backgroundImage]];
}
else
{
    UIImage * backgroundImage = [UIImage imageNamed:@"bgimage.png"];
    backgroundImageView = [[UIImageView alloc] iniWithImage:backgroundImage]];
}

Any tips/advice is much appreciated!

Thanks!

like image 881
Luke Irvin Avatar asked Sep 18 '12 20:09

Luke Irvin


People also ask

Where are iPhone background images stored?

Go to Settings>Wallpaper.


2 Answers

The following code checks the size / bounds of the screen. If the screen is 586 points (remember, that the screen is measured in points because of Retina) than we know that it is the new 4-inch Retina Display.

if ([[UIScreen mainScreen] bounds].size.height == 568)
{
   UIImage * backgroundImage = [UIImage imageNamed:@"[email protected]"];
   backgroundImageView = [[UIImageView alloc] initWithImage:backgroundImage];
}
else
{
   UIImage * backgroundImage = [UIImage imageNamed:@"bgimage.png"];
   backgroundImageView = [[UIImageView alloc] initWithImage:backgroundImage];
}

See also iOS 6 apps - how to deal with iPhone 5 screen size?

like image 161
Bryan Avatar answered Sep 27 '22 18:09

Bryan


Bryan's answer above worked for me, except that I had to use

[self.bgImageView setImage:backgroundImage];

rather than

backgroundImageView = [[UIImageView alloc] initWithImage:backgroundImage];

The correct image only displays if I use the former.

like image 37
alisonc Avatar answered Sep 27 '22 19:09

alisonc