17

I have an iPhone xib I want to turn into an iPad xib. In Xcode 3 there was a "Create iPad Version" menu option. How do I do this in Xcode 4?

I currently resized my xib, but when I turn on the simulated items (Navigation Bar, etc.) it shrinks the view back down to iPhone size.

Collin
  • 6,720
  • 4
  • 26
  • 29

9 Answers9

54

This worked for me:

  1. Make a copy of the .xib in the Finder.
  2. Open the copied file in a text editor.
  3. Change "com.apple.InterfaceBuilder3.CocoaTouch.XIB" to "com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB".
  4. Change all instances of "IBCocoaTouchFramework" to "IBIPadFramework".
  5. Search for sizes like {480, 320} and edit them. Or just reopen the file in Xcode and use the GUI to resize items as needed.

This also works in reverse, if you need to change an iPad xib into an iPhone xib.

arlomedia
  • 8,534
  • 5
  • 60
  • 108
  • 4
    you don't need to open the new xib in a text editor. You can open the copied xib in xcode 4 in a "source code" mode, right click on the copied xib, then under "open as" select "source code". edit the code directly. (then when done, select "interface builder" instead) – hokkuk Mar 24 '12 at 17:52
  • 15
    also, you don't need to search for those sizes of views to change there, you can save the copied xib after the two edits you suggest, (get it back into IB format as above comment) then highlight (select) your main view controller or uiview of that new xib then go into the attributes inspector (looks like a slider control far right column in xcode) of the copied xib, and under "size" select "ipad full screen" then rearrange the sub views to your liking. – hokkuk Mar 24 '12 at 18:10
  • 1
    totally agree.. also "size" select "ipad full screen" is a very nice way as told by @hokkuk .. no need to search for sizes :D – Zaraki Jul 20 '12 at 09:06
  • 1
    just wanted to share a command-line tool I made based on your answer: http://iphone.dizzystudios.net/ConvertToiPad – Dimitar Marinov Apr 13 '13 at 07:28
  • Also need to change targetRuntime="iOS.CocoaTouch" to targetRuntime="iOS.CocoaTouch.iPad" – hknkrt Dec 13 '13 at 16:18
14

in Xcode 4 it's quite hidden, but the option to convert XIBS in the app still exists.

Select the target (in XCODE4 it's shown when you select the project). Once selected use the contextual menu to "Duplicate" it. It will ask if you want to "Duplicate and transition to iPad". Then all the XIBS will be duplicated with the new iPad size.

Marc M
  • 974
  • 10
  • 9
  • That is nice to know, but I'd still like to convert them one .xib at a time. – Collin Sep 03 '11 at 14:23
  • 8
    Note that your target has to be "iphone" for the "transition to iPad" option to show. Universal won't let it appear. – Ben G Oct 28 '11 at 13:52
7

On assessing my options, these were my thoughts:

  • Too much of a hassle to install xcode 3 and downgrade project
  • Don't want to mess with .xib file format - afraid it might break something that will show itself much later
  • Copying the same nib is imperfect (see the explanations in this thread)

So finally, what I ended up doing that works fine is:

  1. Create a new file, choose "UIViewController derived" class
  2. Check the "intended for iPad" checkbox
  3. Name the file -iPad
  4. Delete the .h and .m corresponding to the uiviewcontroller
  5. Now populate the new nib with the same objects, structure and connections as the original nib
  6. Check if on iPad, if so then load the new nib else load the old nib
er0
  • 1,746
  • 2
  • 16
  • 31
  • 3
    "Populate new nib with the same objects" can apparently be done by copy pasting, which kinda shortens the entire process... – Oded Ben Dov Oct 15 '11 at 17:08
  • 2
    rather than "choose uiviewcontroller" class, it could be a little easier to just "create new file" and go into the "user interface" section of iOS, there choose "Empty".. click next, choose iPad. then drag a UIViewController to it... however arlomedia's answer i would say is a little easier with the added comments below his answer. – hokkuk Mar 24 '12 at 18:20
2

The 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).

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

Another simple way in XCode4 is: Just copy the iPhone XIB in Finder; drag the copy in your project. Open the copied XIB in XCodes build in interface builder. Change the size of the top view in your NIBs hirarchy to iPads dimensions (e.g. 1024x748 for landscape with statusbar) - everything else resizes according to the autoresizing masks. Works perfect for me.

Oliver
  • 19
  • 1
  • 2
    This works until you want to simulate items (Navigation Bar, etc.) and then it automatically shrinks back down to iPhone size. – Collin May 05 '11 at 13:07
0

Using XCode 4, all you have to do is select the (iPhone-specific) .xib file in the project navigator, then select File... --> Duplicate...

Name the new .xib file the same as your iphone-specific one, but append ~ipad to the name. All your previous connections in the view hierarchy should be unchanged in your brand-new iPad-specific .xib file.

Free Mason
  • 107
  • 5
0

You can use this tool I made, based on the answer from "arlomedia":

http://iphone.dizzystudios.net/ConvertToiPad

just give it the iPhone xib path

Dimitar Marinov
  • 922
  • 6
  • 14
0

If you make a new nib, it will ask you if it should be sized for iPad. That might be the easiest unless you've already done a bunch of work on it.

Walter
  • 5,867
  • 2
  • 30
  • 43
  • Yeah, I have nibs from my iPhone project I want converted to iPad format. Currently, I just stretched them out, but them the simulated features don't work. – Collin Mar 19 '11 at 12:15
0

You will have to use the older version of Interface Builder to use the "Create iPad version using autoresizing masks". There currently is no option in Xcode 4 that will do this.

WrightsCS
  • 50,551
  • 22
  • 134
  • 186