Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Universal Storyboard?

In the old XIB world of iOS development, I was able to create one View Controller and one XIB, and use them for both the iPhone and iPad environments. With just a few code tweaks, the XIB would resize and adjust to fit the different dimensions and aspect ratios. This allowed me to reduce the risk of the two layouts getting out of sync over time.

Is the same thing possible in the world of Storyboards? By default Xcode creates two distinct storyboards for my Universal app -- one for the iPhone and one for the iPad.

How can I use one storyboard for both?

Thanks!

Updated:

Size Classes in Xcode 6 will essentially achieve the goal of Universal Storyboards. More info here:

https://developer.apple.com/library/prerelease/ios/documentation/DeveloperTools/Conceptual/WhatsNewXcode/Articles/xcode_6_0.html

like image 526
Axeva Avatar asked Oct 06 '13 16:10

Axeva


People also ask

Is storyboard better than SwiftUI?

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.

Will SwiftUI replace storyboard?

There is no direct way of migrating from storyboard to swift UI. This compels a developer to continue the use of the storyboard for existing apps and in lower versions. Since, it is very new so there is less community support which is not the case for storyboard.

How do I find my storyboard code?

Select the storyboard in the navigator, right click and select 'Open As'. You should see 2 options 'Interface Builder - Storyboard' or 'Source Code' - select the Source Code option should fix your issue.

How do I make multiple storyboards in Xcode?

1. Create storyboards by File -> New -> File -> Select Storyboard -> Next -> Give it a name -> Create. In this demo, we will create 3 storyboards, Shopping, Checkout and Profile. Including the Main which was given when the project is created, we will have 4 storyboards in total.


1 Answers

In short...you can't.

There's a workaroud I use to create the iPad storyboard at the end of the iPhone development.

You have to locate the iPhone story board and using the Terminal you can duplicate it giving it the name of the iPad storyboard that Xcode has created for you. Delete the empty old storyboard and open the newly copied one changinge the targetRuntime attribute to "iOS.CocoaTouch.iPad" instead of the old value "iOS.CocoaTouch".

Open the iPad storyboard with Xcode, everything is there but it still needs to be arranged and connected to the ViewController (wiring stuff included..). It's not perfect but I usually do it to save some error prone copy and paste (and several hours as well).

If you just want to target your app for iPhone and deliver it to iPad you can just use the iPhone Xib and you'll get the 2x little botton in your right corner.

Update late 2014 (after Xcode 6 beta release)

Xcode 6 now allows you to define a single storyboard and through the size classes concept, to make it adapt to all their devices. This solution is a bit confusing (especially if you're familiar with how this problem is solved in the Android environment) but it's something in the right direction IMHO.

like image 103
elbuild Avatar answered Oct 21 '22 10:10

elbuild