78

How do you do it? I saw one video tutorial on it, but the screen was too small. Also, other than changing the view size, are there any other major changes I would have to make to my iphone apps to convert to iPad?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
NextRev
  • 1,711
  • 4
  • 22
  • 31

17 Answers17

160

I was able to narrow it down to a few things, so here are the steps that worked for me:

1) Make a copy of the iPhone xib file and add it to your project

2) Right click the file (in xcode) and Open As > Source Code

3) The 2nd line should look like:

<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.10">

Replace with:

<archive type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="7.10">

4) Search for "IBCocoaTouchFramework" and Replace all occurrences with "IBIPadFramework"

5) Save the file and Open As > Interface Builder - iOS

The file might still look like a regular iPhone xib, but for me, once I changed the Status Bar to "Black" in the Attributes inspector the rest of the xib just kind of "snapped" into an iPad xib

Jag
  • 1,744
  • 2
  • 11
  • 11
  • 1
    Worked. My status bar was already black. I set it to none and back to black then it snapped to the iPad view – Thomas Oct 25 '11 at 08:36
  • 4
    Awesome. Definitive answer for Xcode 4. The one with all the upvotes is way outdated :) – Chris Newman Oct 28 '11 at 17:44
  • Excellent! Without this It would have taken hours to recreate the bindings between my gfx-components and their outlets in the controllers. Thanks a lot! – tommys Feb 18 '12 at 12:43
  • 1
    I just want to add that this answer works in Xcode 4.2. Thanks – jsherk Apr 02 '12 at 00:11
  • 4
    As you might expect, this method works the other way around, too, for cases where you've created an iPad resource first and want to work back to an iPhone one. – chrisbtoo May 29 '12 at 04:32
  • 1
    If you want an automated workflow based on this great answer, I got you covered: http://stackoverflow.com/a/12741197/272342 – Guillaume Oct 05 '12 at 07:12
  • 1
    If the device isn't changing in your nib after you do this, you may have had the "Size" in the Attribute inspector selected as Free form. If you change to iPad full screen it will become an iPad – corbin Feb 01 '13 at 19:16
  • thanks jag, it's really Time saving for all developers. if you have maintain proper "autoresizingmask" it will be amazing. and really great answer. – kalpesh jetani Mar 01 '13 at 12:19
  • 7
    Note that in the latest XCode5, this had changed just a bit. Instead of looking for "IBCocoaTouchFramework" in step 4, look for "iOS.CocoaTouch" and simply add ".iPad" to the end. There is only one occurrence, and it is on the same line as the first edit. Also note that when you open this in IB, simply swap it to Portrait or Landscape (which ever it is not) and back again, and it will resize just fine. – MajorHavoc Nov 14 '13 at 05:15
33

In Xcode 5 you should just:

Find:

<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="4510" systemVersion="12F37" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">

Replace by:

<document type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="3.0" toolsVersion="4510" systemVersion="12F37" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none">

Note we are just adding .iPad to the type and targetRuntime properties.

After opening just select a new Size to adjust. Example: iPad Full Screen.

Nikolai Samteladze
  • 7,699
  • 6
  • 44
  • 70
SebastianView
  • 842
  • 10
  • 8
29

Assume you've the SDK with Xcode 3,

  1. Open IB.
  2. Open the XIB.
  3. File -> Create iPad version using autoresizing masks.
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
  • What differences can be expected? – pestilence669 Mar 21 '10 at 23:23
  • 7
    Uh... except there is no Interface Builder anymore, and no equivalent option in XCode 4 that I can find. – Nicholas M T Elliott Mar 22 '11 at 01:14
  • I've looked all over for the solution this in Xcode 4, I have had to rebuild my XIB as iPad from scratch to solve it so far, which can't be right. – Peter Johnson Mar 26 '11 at 22:34
  • @Peter Johnson, @radven, @Nicholas M T Elliot, put an answer below that actually works (though it ain't pretty) for XCode 4. – Dan Rosenstark Jul 04 '11 at 17:57
  • 1
    One thing that may help- if you turn off simulated interface elements you can then resize your view freely. – Peter Johnson Jul 22 '11 at 13:54
  • I found that selecting "using autoresizing masks" simply scaled everything up (not keeping the aspect ratio) and ended up having to resize the view once I opened it in Xcode 4. Selecting the other option might have done what I wanted without extra work. – Thom Mahoney Aug 16 '11 at 16:27
22

XCode4:

In xcode 4 we can't do that for a single xib,but we can create respective ipad versions all at once.

Before configuring your project to ipad,when it is configured only for iphone, right click on target and click on duplicate.

Now select "duplicate and transition to ipad".A new target and new set of xibs are created.It should reduce some work.

Hope it helps.

Tejesh Alimilli
  • 1,782
  • 1
  • 21
  • 31
  • this saved lots of my time...This one is the right answer for this question :) – Guru May 22 '13 at 15:39
  • Unfortunately this doesn't work in Xcode 5.1, it creates the new iPad target but doesn't migrate the xib. I even tried creating a fresh project and copying the storyboard to Main.storyboard, then duplicating the target to iPad, and it still doesn't generate the xib. For some reason Interface Builder from Xcode 3 no longer opens in 10.9, so I'm forced to edit the xib text directly. – Zack Morris Mar 18 '14 at 21:41
  • P.S. this answer worked the best for me in Xcode 5 (possibly 4 as well), because it automatically resized the layout for the most part: http://stackoverflow.com/a/8694985/539149 – Zack Morris Mar 18 '14 at 21:59
14

Xcode 4:

The Create iPad Version Using Autosizing Masks feature has been removed from Xcode 4. Right now the easiest way is to use Xcode 3 for the conversion, since the nib (.xib) file format did not change.

Xcode 3 & 4 can now be both installed on the same system by simply selecting a different folder (see installation instructions on the disk image).

Otherwise you will need to copy/paste the UI elements from the iPhone version, and re-link them to your code.

antalkerekes
  • 2,128
  • 1
  • 20
  • 36
6

What about letting the computer do computer's job?
Faster, less risk of errors.

Here is a workflow based on the excellent answer from Jag, but automated with sed.

First, let's setup some stuff. We will only need to do this once.
In the directory that contains your XIBs, create two files with the following content:

File iPhoneToiPadXIBConversion.sed:

s/com.apple.InterfaceBuilder3.CocoaTouch.XIB/com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB/g
s/IBCocoaTouchFramework/IBIPadFramework/g

and file iPadToiPhoneXIBConversion.sed:

s/com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB/com.apple.InterfaceBuilder3.CocoaTouch.XIB/g
s/IBIPadFramework/IBCocoaTouchFramework/g


Setup is now finished. To convert a XIB, enter one of the two following commands in the terminal:

iPhone to iPad conversion:

sed -f iPhoneToiPadXIBConversion.sed  MyViewController~iphone.xib  > MyViewController.xib

iPad to iPhone conversion:

sed -f iPadToiPhoneXIBConversion.sed  MyViewController.xib  > MyViewController~iphone.xib





Just for the fun, let's create two function in zsh, to make the conversion even more simple:

function convertiPadXIBToiPhone () {
    newXibName=`echo "$1" | /usr/bin/sed "s/.xib/~iphone.xib/"`
    `/usr/bin/sed -f iPadToiPhoneXIBConversion.sed "$1" > "$newXibName"`
    echo "Did convert $1 to $newXibName."
}

function convertiPhoneXIBToiPad () {
    newXibName=`echo "$1" | /usr/bin/sed "s/~iphone.xib/.xib/"`
    `/usr/bin/sed -f iPhoneToiPadXIBConversion.sed "$1" > "$newXibName"`
    echo "Did convert $1 to $newXibName."
}

After having added this to your zsh config, converting a XIB is a simple as:

convertiPadXIBToiPhone MyViewController.xib

or

convertiPhoneXIBToiPad MyViewController.xib
Community
  • 1
  • 1
Guillaume
  • 21,685
  • 6
  • 63
  • 95
  • ALmost as nice as when XCode 3 has this built in. :-) – Warren P Feb 25 '13 at 17:01
  • :) Hey, I would love to have this hack made useless by a new feature by the next version of Xcode. Waiting for it, I use it each time I must convert a XIB and it works great! – Guillaume Feb 26 '13 at 17:37
5

Open up the XIB in XCode 4 using "view as source code."

Before

Back up the nib in question.

One

Substitute this goo

    <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
    <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
        <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string>
        <integer value="1056" key="NS.object.0"/>
    </object>
    <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
        <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3</string>
        <integer value="3100" key="NS.object.0"/>
    </object>
    <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
    <int key="IBDocument.defaultPropertyAccessControl">3</int>
    <string key="IBCocoaTouchPluginVersion">301</string>

for this other goo

    <string key="IBDocument.TargetRuntimeIdentifier">IBIPadFramework</string>
    <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
        <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3</string>
        <integer value="3100" key="NS.object.0"/>
    </object>
    <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
    <int key="IBDocument.defaultPropertyAccessControl">3</int>
    <string key="IBCocoaTouchPluginVersion">301</string>

Two

Then, for each view in the nib using the integrated IB, delete it and then hit undo.

Three

Then shower in hot water to wipe off that disgusting feeling you might have.

Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421
4

You can open the XIB as textfile and change the UIView size:

Right click on your XIB file in de navigator and select: "open as..." Open as source file.

Find the UIView reference and change the Frame values:

<object class="IBUIView" id="191373211">

<string key="NSFrame">{{0, 20}, {768, 1024}}</string>
wasigh
  • 895
  • 1
  • 11
  • 21
3

In XCode 4.3.2, the easiest way for me to create iPad version of xib is duplicating that xib file and add ~ipad suffix to the filename. And add both "myVC.xib" and "myVC~ipad.xib" into your project. Note that it is "~ipad" NOT "~iPad". Your app will use that ~ipad version automatically when run on iPad. This also works with resource files (e.g. images).

The best reference I could find at the moment... https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/LoadingResources/ImageSoundResources/ImageSoundResources.html

Hlung
  • 13,850
  • 6
  • 71
  • 90
  • I heard this (automatically selecting file with "~iPad" ) has an issue with older iOSes. – karim Feb 08 '13 at 15:23
  • Yeah, but that's a typical thing with new features. Can't find a good document for this though. But I'm pretty sure it works with iOS 5 and above, which should be good enough. – Hlung Feb 21 '13 at 07:08
  • Strange that Apple still uses [[UIDevice currentDevice] userInterfaceIdiom] in it's universal app template. – Timur Kuchkarov Mar 01 '13 at 04:43
3

Xcode 5 update

targetRuntime="iOS.CocoaTouch"

to

targetRuntime="iOS.CocoaTouch.iPad"

0oneo
  • 695
  • 7
  • 10
2

I will document what I did in Xcode 4.5:

  1. fixpattern.sh

    cp REPLACEME_Iphone.h REPLACEME_Ipad.h
    sed -e 's/REPLACEME_Iphone/REPLACEME_Ipad/g' REPLACEME_Ipad.h > REPLACEME_Ipad_tmp.h
    mv REPLACEME_Ipad_tmp.h REPLACEME_Ipad.h
    cp REPLACEME_Iphone.m REPLACEME_Ipad.m
    sed -e 's/REPLACEME_Iphone/REPLACEME_Ipad/g' REPLACEME_Ipad.m > REPLACEME_Ipad_tmp.m
    mv REPLACEME_Ipad_tmp.m REPLACEME_Ipad.m
    cp REPLACEME_Iphone.xib REPLACEME_Ipad.xib
    sed -e 's/com.apple.InterfaceBuilder3.CocoaTouch.XIB   /com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB/g' REPLACEME_Ipad.xib > REPLACEME_Ipad_tmp.xib
    mv REPLACEME_Ipad_tmp.xib REPLACEME_Ipad.xib
    sed -e 's/IBCocoaTouchFramework/IBIPadFramework/g' REPLACEME_Ipad.xib > REPLACEME_Ipad_tmp.xib
    mv REPLACEME_Ipad_tmp.xib REPLACEME_Ipad.xib
    sed -e 's/320, 416/768, 1004/g' REPLACEME_Ipad.xib > REPLACEME_Ipad_tmp.xib
    mv REPLACEME_Ipad_tmp.xib REPLACEME_Ipad.xib
    sed -e 's/REPLACEME_Iphone/REPLACEME_Ipad/g' REPLACEME_Ipad.xib > REPLACEME_Ipad_tmp.xib
    mv REPLACEME_Ipad_tmp.xib REPLACEME_Ipad.xib
    
  2. Create a list of file you want to convert in fixfile, each line will be a file name without extension. If you original file name is AAA_Iphone.h, just put AAA. If your original file is not of this pattern, you need to revise the script.

  3. Run in command line

    cat fixfile | while read line ; do sed -e "s/REPLACEME/${line}/g" fixpattern.sh ; done > fixall.sh
    
  4. Review and run fixall.sh

  5. Add newly created file into project

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
2

Jag's answer is great. But there is a catch if an XIB is opened/ created in Xcode 5.

For Xcode 5

1) Make a copy of the iPhone xib file and add it to your project

2) Right click the file (in xcode) and Open As > Source Code

3) The 2nd line should look like:

<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="4510"

change it to

<document type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="3.0" toolsVersion="4510"

4) 8th line should look like this:

<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>

change it to

<rect key="frame" x="0.0" y="64" width="768" height="960"/>

That's it and there you have iPad XIB. But still the real credit goes to Jag.

Evol Gate
  • 2,247
  • 3
  • 19
  • 37
1

In addition to answer given by Jag also search for "320,460" and replace it with 768,1024 and your XIB will be resized to iPad dimensions.

1

For Xcode 4,

You need not create separate target for each device. Instead, you can change the Devices in project summary to Universal which would be in iPhone already. This is answered in the link Updating iOS 5 App to Universal on Xcode 4.2. Thus, it will do transition for you.

aparna
  • 353
  • 2
  • 3
  • 13
0
Jag has given Great Answer.

In Some Cases.

No need to convert your Iphone XIB in Ipad XIB . You can Use Autoresizingmask and get Running Ipad also. just need to configure your APP for running in Universal mode with proper autoresizingmask.

kalpesh jetani
  • 1,775
  • 19
  • 33
0

Just replace

<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14854.2" targetRuntime="iOS.CocoaTouch"

with

<document type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="3.0" toolsVersion="14854.2" targetRuntime="iOS.CocoaTouch.iPad"
Tony Pham
  • 393
  • 1
  • 3
  • 9
0

Sounds like the best solution is to always develop as iphone first, then once you are complete done, add the ipad target, letting xcode do the update. I made the same mistake, selected universal to start, which creates the first few files, but then every other xib had to be hand recreated in the ipad folder. Big PAIN

nwestwood
  • 21
  • 5