How to make splash screen fit for both landscape and portrait in ios

I'm making a splash screen, but problem is, when i change to landscape , it will not fit the screen, so, how can i fix this

Here is on portrait mode:

enter image description here

And when switch to landscape: enter image description here

So how to fix this? Thank you guy a lots

Upvotes: 0

Views: 1470

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347184

So, the first thing I do is seperate the background from the logo. As a "general" rule of thumb (for me) I try and keep the logo within about 300x300 (@ x1), but you could also make constrain the width and/or height the logo to the view's width/height. Applying a ratio constraint would also allow you to scale the logo as a percentage of the view, while maintaining its aspect ratio (or just use "Aspect Fit" on the UIImageView), but every splash screen seems to want to be slightly different.

I drop a UIImageView onto the launch view and, making sure to turn off "Constrain to Margin" and ensure I'm referencing the UIView and not the "Safe Area", pin it to all the edges

A place to start

I then assign the image I want to use as the background to UIImageView and select "Aspect Fill" to ensure that the aspect ratio is maintained, but it will fill (or overflow) all the available area of the image view

Background

Next, I add another UIImageView. Here I setup the sizing constraints for the image. In my case, I made a square logo of 300x300px so I don't need to mess about with it and the constrain it to be centred in the launch view

A logo to call my own

Then I apply the logo image I want to use and ensure the UIImageView is set to "Aspect Fit" (which is now default for Xcode 11+)

All those settings

Also note that I've offset the UIImageView's vertical position so it's slightly offset from the middle, don't ask me why, but it looks weird been in the middle.

You can then use the storyboard editor to explore the various devices and orientations

iPhone

iPad

You could also explore things like "size class" so you could customise how the layout changes between different device "size classes", but I think that would be overkill for something like this

Upvotes: 1

Related Questions