Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode storyboard: Why does the iPad storyboard show iPhone sized views?

Tags:

I have a universal app that uses storyboards. There is an iPhone storyboard and an iPad storyboard. However, in interface builder, the viewcontrollers for the iPad storyboard are still sized for the iPhone. How do I get the iPad storyboard to show iPad sized view controllers?

I realize that the view controller display in interface builder is design-time-only eye-candy, but having iPhone sized VCs makes it really hard to lay out the UI correctly.

like image 277
memmons Avatar asked Mar 26 '12 17:03

memmons


People also ask

Why is Main storyboard not showing up in Xcode?

You have SwiftUI enabled in your project, which does not use storyboards anymore. Your layout is inside the ContentView. swift file. If you do want to work the old way, with storyboards, you should uncheck 'Use SwiftUI' in the project creation screen.

How do I add views to my storyboard?

Specifying the Initial View Controllerstoryboard and select the Tab Bar Controller Scene. On the right, select the Attribute inspector. You'll find a checkbox named Is Initial View Controller. Checking this box will identify the selected view controller as the initial entry point for the storyboard you're on.

Is SwiftUI or storyboard easier?

Storyboard Advantages over SwiftUIIt is easier to use Storyboard as a beginner . Storyboard consist of Xib and custom View which can be reusable in the projects. It is easier to build an app as there is only drag and drop of the elements of the storyboard.


2 Answers

After some digging through the storyboard source code, it turns out that the iPad storyboard was copied from the iPhone storyboard. So, the question really became how do I convert an iPhone storyboard into an iPad storyboard?

The answer is surprisingly simple. I ran across this SO answer -- to convert an iPhone storyboard to an iPad storyboard, do the following:

  1. From Xcode, right-click on the storyboard and choose Open As -> Source code

  2. Search for targetRuntime="iOS.CocoaTouch"and change it to targetRuntime="iOS.CocoaTouch.iPad"

  3. Right-click on the storyboard again and choose Open As -> iOS Storyboard

The storyboard will now show all views in the correct size.

like image 96
memmons Avatar answered Sep 20 '22 09:09

memmons


When you first create a storyboard you select a Device Family (iPhone or iPad) that the storyboard is targeted for. I don't know of a way to change the device family once the storyboard has already been created.

However, to solve your problem I recommend the following:

Create a new storyboard by going to: New -> File -> User Interface -> Storyboard (Be sure to select Device Family = iPad when choosing the options.)

Go to your old storyboard, select and copy everything by pressing Command-A, Command-C. Then go to your and paste everything by pressing Command-V. Your view controllers will now be iPad-sized.

You can then delete the old storyboard and rename your new storyboard to whatever the old name was.

like image 36
jonkroll Avatar answered Sep 20 '22 09:09

jonkroll