resting
resting

Reputation: 17467

Change background image between iphone 4 and iphone 5 in storyboard?

I have 2 background images built for the specific devices (320x480) and (640x960). I have done the iphone 5 storyboards.

Now, how can I change the background image to the (320x480) version when viewed on a iphone 4?

Note auto layout wouldn't work for me in this case since it's not an alignment issue but rather the image itself.

Upvotes: 1

Views: 423

Answers (3)

Alex Cio
Alex Cio

Reputation: 6052

I always include these macros inside my .pch file:

#define isiPad  ([[UIScreen mainScreen] bounds].size.height == 1024)?TRUE:FALSE
#define isiPhone4  ([[UIScreen mainScreen] bounds].size.height == 480)?TRUE:FALSE
#define isiPhone5  ([[UIScreen mainScreen] bounds].size.height == 568)?TRUE:FALSE

So you can create a switch and set the specific UIImage you need for the screen. I also created a gist with some more useful marc

Upvotes: 1

Augie
Augie

Reputation: 1341

Name 320x480 image "background.png" Name 640x960 image "[email protected]" Name 640x568 image "[email protected]"

then in story boar set background image to "background"

you can also set all these up in an assets.xcassets file in the same image set to simplify.

Upvotes: 3

Jack
Jack

Reputation: 16855

See How to detect iPhone 5 (widescreen devices)?

Simply set the image in viewDidLoad after you've checked the device

Upvotes: 1

Related Questions