Choose different background image for iPhone and iPad launch screen

Viewed 956

I built an iPhone app whose background image fit nicely for iPhone screens, but when I run at iPad, this image stretch horizontally (as the iPad screen is more squared than the iPhone).

Is there a way for me to choose which background image is going to be loaded?

I know that I can use UIDevice.current.userInterfaceIdiom == .phone and UIDevice.current.userInterfaceIdiom == .pad to check which device I'm in but how can I choose the correct image if Launch Screen doesn't accept code attached to it?

2 Answers

The easiest way to do this that I can think of is to have two devices in your image set of located in your Assest.xcassets. Then assign different images as you like in the two devices, iPhone and iPad, like so:

enter image description here

Then here's the preview when you run the app on the iPhone (left), and on the iPad (right). Two different images in each kind of device.

enter image description here

In your LaunchScreen.storyboard file, you likely have a UIImageView that contains your image. When you click on that image view, you will see details of the view in right slider view. Set the view's content mode to "center" and you will be all set. You can also use "aspect fit" or "aspect fill" if center doesn't work.

enter image description here

Related