Converting iPhone xib to iPad xib?

后端 未结 17 2716
一向
一向 2020-11-27 09:31

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

相关标签:
17条回答
  • 2020-11-27 10:10

    Xcode 5 update

    targetRuntime="iOS.CocoaTouch"

    to

    targetRuntime="iOS.CocoaTouch.iPad"

    0 讨论(0)
  • 2020-11-27 10:12

    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.

    0 讨论(0)
  • 2020-11-27 10:17

    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>
    
    0 讨论(0)
  • 2020-11-27 10:17

    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

    0 讨论(0)
  • 2020-11-27 10:19

    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
    
    0 讨论(0)
提交回复
热议问题