Converting iPhone xib to iPad xib?

16 Solutions Collect From Internet About “Converting iPhone xib to iPad xib?”

Assume you’ve the SDK with Xcode 3,

  1. Open IB.
  2. Open the XIB.
  3. File -> Create iPad version using autoresizing masks.

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

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.

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.

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.

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

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.

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>

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

Xcode 5 update

targetRuntime=”iOS.CocoaTouch”

to

targetRuntime=”iOS.CocoaTouch.iPad”

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

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.

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.

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.

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

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.