IPhone to iPad

Source: Internet
Author: User


IPhone to iPad:


  • Method 1Modify the device target settings (normal mode: a set of code and XIB interface files. The code is divided into if and Else To process multiple devices respectively)

By default, all iPhone programs run on their original screen size of 320x480 (non-full screen). If you want your program to run on the iPad, in full screen mode, you need to modify the Project Settings and select your targeted device family as the iPhone/iPad (this mode enables your program to automatically detect the running device type, and make your program display in full screen ).

  1. Switch the IOS version running on the iPhone to the version running on the iPad. (The current iPhone IOS system version is 4.1, and the iPad version is 3.2 ).
  2. Modify the target device family (select the targeted device family in the build as the iPhone/iPad ).


Now you can run your program on the iPad. However, you will see that your UI is exactly the same as that under the iPhone, which is not what we need. Therefore, redeploying your views is the programmer's responsibility, that is, reposition views.

First, we need to manually check the running device type. (Use the pre-compiled command)

# If (_ iphone_ OS _version_max_allowed >=30200)

Nsstring * STR;

If (ui_user_interface_idiom () = uiuserinterfaceidiompad ){

// IPad version code;



// IPhone/iPod Touch version code;

# Endif


# Define ispad (ui_user_interface_idiom () = uiuserinterfaceidiompad ). The returned value of the ui_user_interface_idiom () method is uiuserinterfaceidiomphone or uiuserinterfaceidiompad.


Method 2Create a Common Program (two sets of code and XIB interface files, two sets of code and interface are irrelevant)

The disadvantage of the previous method is that you must write two versions (iPhone/iPod and iPad) of code to adapt to different platforms, at the same time, it is a challenge to dynamically modify the UI layout (and the widget size), but it is also very painful. Therefore, Apple recommends that you create a "universal" application. Such applications can run under the iPhone and iPad. This requires the corresponding. H,. m, and. XIB files for each platform. The background Business Code must be written in the. h and. M files of the corresponding version.

  1. Upgrade the device of the project to the iPad. In essence, xcode changes the targeted device family settings of the project to the iPhone/iPad. Xcode will create a copy of The mainwindow. XIB file and name it a MainWindow-iPad.xib. The two files contain the "projectname" viewcontroller. For example:
  2. Add the XIB file of the corresponding iPad version to the resource-iPad folder. Naming rules: "iPad" Features "viewcontroller. XIB" (or "function" viewcontroller-iPad. XIB ") to generate. H,. M,. XIB files. And connect these iPad versions of xxviewcontroller to the MainWindow-iPad.xib (same as the normal iPhone version ).
  3. In this way, you can select different simulators to see the Interface Effects of the corresponding versions processed by the same set of code.


  1. Note: Select upgrade the device target for iPad. xcode changes the targeted device family settings of the project to the iPhone/iPad. Mainwindow. xib and the MainWindow-iPad.xib serve as the entry for two versions, and other corresponding versions of viewcontroller connect to their own mainwindow (-iPad). XIB file.
  2. The result is:
  3. Method 3Maintain two sets of UI libraries (one set of code, two sets of XIB interface files, and one set of common code)

In this case, you will get two executable bodies (executables), one for iPhone/iPod Touch, and the other for iPad.

  1. Create an iPhone application and upgrade it to IPAD compatibility. The method is the same as method 2. The method 2 selects one universal application, and the two device-specific applications is selected here.


In this case, unlike method 2's-iPad files, the iPhone files are directly copied to the resource-iPad folder with the same name. The Code only needs one copy, but you only need to set the file's owner of xxviewcontroller in the resource and resource-iPad folders to the same xxviewcontroller class in the classes folder, other UI elements are set to connect to the file's owner. At the same time, two versions of executables, "projectname". app and "projectname"-upgraded. app are generated.

The result is that the same result interface is processed by the same set of code.


Conclusion: The actual project background generates many controls, especially tableview. To adapt to iPhone and iPad, you can consider the third method, one set of code and two sets of XIB interfaces. When loading the background, use:


If (isipad ){

Uitableviewcontroller * tableviewcontroller = [[uitableviewcontroller alloc] initwithnibname: @ "ipadxxviewcontroller" Bundle: Nil];


Else {

Uitableviewcontroller * tableviewcontroller = [[uitableviewcontroller alloc] initwithnibname: @ "iphonexxviewcontroller" Bundle: Nil];


You can. Ipadxxviewcontroller and iphonexxviewcontroller represent the corresponding ipadxxviewcontroller. XIB and iphonexxviewcontroller. XIB files respectively.

I hope it will be useful to you.

Statement: To sum up the above content, I have only limited my ownership of this article to the final summary.











Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.