Xcode 4 .xib Create iPad Version

2020-01-27 14:08发布

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.

9条回答
We Are One
2楼-- · 2020-01-27 14:40

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.

查看更多
劳资没心,怎么记你
3楼-- · 2020-01-27 14:41

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
查看更多
闹够了就滚
4楼-- · 2020-01-27 14:43

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.

查看更多
登录 后发表回答