Adding iPad support to your iOS app
The screen sizes vary for iPad and iOS apps, which requires different constraints every time you switch your device.
One approach to this is of course the “Vary for Traits” where you give a specific constraint for each trait.
But another approach could be adding a whole new storyboard just for the iPad. This gives you much more flexibility to align your items separately and give the necessary constraints keeping the orientations in mind.
Well, it's pretty simple. Here's how
- Copy the story board of your iOS app and paste it, rename it to “Login_iPad.storyboard”.
- So now you will have 2 storyboards — “Login.storyboard” and “Login_iPad.storyboard”.
- For the “Login_iPad.storyboard” double click and select Open As->Source Code.
- Change targetRuntime=”iOS.CocoaTouch" to targetRuntime=”iOS.CocoaTouch.iPad”
- How will you decide which storyboard to display? You need to just check for the device and select the storyboard accordingly.
if UIDevice.current.userInterfaceIdiom == .phone {
initialStoryboard = UIStoryboard(name: “Login”, bundle: nil)
} else {
initialStoryboard = UIStoryboard(name: “Login_iPad”, bundle: nil)
}
Note: Make sure you add the new storyboard in the Compile Sources section of the Build Phases, remove it if there's an extra copy of it.
That’s all!😊 Drop in your thoughts or suggestions in the comment section.