Universal iPad/iPhone XIBs - Xcode 4

前端 未结 6 1006
忘了有多久
忘了有多久 2021-02-06 18:50

I want to make a universal app which has two different XIB files. One for iPhone, and one for iPad. They use the same code, just different UIs. How would I create a \"universal\

6条回答
  •  离开以前
    2021-02-06 19:45

    As a start (you say you are creating a view based application), create it based upon either iPhone or an iPad view.

    This will give you an appdelegate, a viewcontroller and a view (tailored for iPad or iPhone dependent upon which option you chose)

    Now add another xib, go to File > New File... look on the left of the dialog and chooser "User Interface" in the iOS group. In the pane on the right, select View and click next, now choose iPad or iPhone (based on what you chose initially) when the xib is created, select it, then select the files owner on the left of the main pane. Then, go to Utilities (right pane) and choose Identity inspector (3rd option icon along the top) there change the class to be the same viewController as was created when you created your view based application. You can bind outlets just the same way on both views but they will share the same viewController.

    Determining which device your app is running on at runtime, you can use the convention

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    

    and base the loading of views upon this kind of conditional statement. Just for clarity, remember you load a nib using its name so you can choose the nib relevant to the environment (above) and the framework will do the rest.

    Be aware that it is never as straightforwards as you might think (if you've never done it before) Apps that make best use of the iPad's real estate generally tend to work better with dedicated views, although this is certainly not always the case. Any dynamically added screen components will need to be coded as such, taking into account the difference in screen space.

    This could easily turn into an essay, I suggest you do some reading, check out source code and dive in. You'll learn a lot just by experimenting.

提交回复
热议问题