The easiest way to ensure that your iPhone application runs as an iPad application (that is, full screen) is to modify the Targeted Device Family setting in your Xcode project. The following Try It Out shows you how to achieve this.
TRY IT OUT: Modifying the Device Target Setting
How It Works
In this example, you first created an iPhone application that you then tested on the iPhone Simulator, simulating both the iPhone and the iPad. By default, all iPhone applications run in their original screen size — 320 × 480 pixels. If you want your iPhone application to run full screen on the iPad, you have to modify the Targeted Device Family setting in your project.
The Targeted Device Family setting provides three different values: iPhone, iPad, or iPhone/iPad. Setting it to iPhone/iPad ensures that your application can automatically detect the device on which it is running, and runs your application full screen.
Notice that the UI of the application is exactly the same as that on the iPhone. It is your responsibility to re-layout your UI when the application is running on the iPad. One way would be to programmatically reposition your views when your application detects that it is running on an iPad. Another way would be to use the Size Inspector window to set the Autosize property of each view on the View window to anchor the view to the edges of the screen. The next section describes how to detect the device on which an application is currently running.
In order to re-layout your UI according to the device on which it is running, it is useful to be able to programmatically detect if your application is running on an iPhone/iPod touch or an iPad. The following Try It Out shows you how.
TRY IT OUT: Detecting the Device
- (void)viewDidLoad { #if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200) NSString *str; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { str = [NSString stringWithString:@“Running as an iPad application”]; } else { str = [NSString stringWithString: @“Running as an iPhone/iPod touch application”]; } UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@“Platform” message:str delegate:nil cancelButtonTitle:@“OK” otherButtonTitles:nil]; [alert show]; [alert release]; #endif [super viewDidLoad]; }
How It Works
The preceding code includes a conditional compilation directive to indicate that if the application is compiled against the minimum iOS version of 3.2, then it will include a block of code to programmatically detect the type of application it is currently running as:
#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200) //---code within this block will be compiled if application is compiled // for iPhone OS 3.2 and above--- #endif
To detect if the application is running on an iPad, you check the result of the UI_USER_INTERFACE_IDIOM( ) function. This function returns the interface idiom supported by the current device. If it is an iPad, then the result of this function will be UIUserInterfaceIdiomPad:
NSString *str; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { str = [NSString stringWithString:@“Running as an iPad application”];
} else { str = [NSString stringWithString: @“Running as an iPhone/iPod touch application”];
If the application is running as an iPhone application (that is, not full screen) on the iPad, the UI_USER_INTERFACE_IDIOM() function will return UIUserInterfaceIdiomPhone.
3.145.128.229