Search code examples
iosxcodeuistoryboardios-universal-app

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


Solution

  • 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.