Converting iPhone xib to iPad xib?

后端 未结 17 2895
一向
一向 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: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
    

提交回复
热议问题