Converting Storyboard from iPhone to iPad

2019-01-01 12:00发布

I have an iPhone application which has a storyboard. Now I want to provide an iPad application too. So I asked me whether there is a function which helps me convert my iPhone storyboard to an iPad storyboard.

To be specific:

Is there a similar function or is there only the manual way ?

21条回答
墨雨无痕
2楼-- · 2019-01-01 12:01

I found out a kind of solution:

  1. Duplicate your iPhone-Storyboard and rename it MainStoryboard_iPad.storyboard

  2. Close Xcode and then open this file any text editor.

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

  4. Change the code in the MainStoryboard_iPad.storyboard from:

    <simulatedScreenMetrics key="destination" type="retina4"/> to

    <simulatedScreenMetrics key="destination"/>

  5. Now save everything and reopen Xcode. The iPad-Storyboard has the same contents as the iPhone-file but everyting could be disarranged.

This saved me hours - hopefully this will help you

查看更多
大哥的爱人
3楼-- · 2019-01-01 12:02

I just change (additionally to the answer from @tharkay):

 <device id="ipad9_7" orientation="landscape">

and works great !

I use this in XCode 8.3.3

查看更多
看淡一切
4楼-- · 2019-01-01 12:03

Go to your Target Summary and change devices to universal, then go down and set the ipad version to any storyboard you like including a copied and renamed one if you like.

查看更多
无与为乐者.
5楼-- · 2019-01-01 12:03

Using the XCode6 Size Classes you no longer need to convert the storyboard to iPad. The same Storyboard can be used for both the iPhone and the iPad, saving you from keeping two files up to date.

The resulting storyboard is compatible with iOS7+.

Read more about this here: https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/AboutAdaptiveSizeDesign.html#//apple_ref/doc/uid/TP40014436-CH6-SW1

Use size classes to enable a storyboard or xib file to work with all available screen sizes. This enables the user interface of your app to work on any iOS device.

查看更多
残风、尘缘若梦
6楼-- · 2019-01-01 12:04

Just for fun, on XCode 5.1 and iOS 7.1 I also needed to change the values of "toolVersion" and "systemVersion" to this:

toolsVersion="5023" systemVersion="13A603"

Without this, the new storyboard file wouldn't compile

查看更多
宁负流年不负卿
7楼-- · 2019-01-01 12:06

This is going the other way, but I was able to do a select all & copy in my iPad storyboard (~35 scenes) and paste it into my iPhone storyboard. The scene sizes were automatically adjusted. I only saw two problems, I had to replace UISplitViewController (since it's only iPad), and the default background became transparent instead of gray (still working on fixing that properly, without manually setting the background for everything).

EDIT: It seems the default background for UITableView in the Attributes inspector is rather strange. I had to manually set the background to "Group Table View Background Color" for grouped table views, and "White Color" for non-grouped table views. It then was displayed as "Default" (I assume since it then matched a hardcoded value). -- Actually, even easier, changing from "Grouped" to "Static" and back seems to reset the default color.

查看更多
登录 后发表回答