While developing universal apps
, we have to write a conditional code
for each device
– the iPad
as well as the iPhone
. In this scenario, the proper use of tilde
can be extremely beneficial.
For example, if you want to push new view controller, then you’d have to write lot of lines (almost 10) of code:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@”MasterViewController_iphone” bundle:nil];
[self.navigationController pushViewController:masterViewController animated:YES];
[masterViewController release];
}
else
{
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@”MasterViewController_ipad” bundle:nil];
[self.navigationController pushViewController:masterViewController animated:YES];
[masterViewController release];
}
How can we differentiate images for iphone and ipad?
For differentiating XIB file for iPhone and iPad :
The magical ~
will help you. You can use it, to differentiate between iPhone and iPad assets / xib
files.
Your file should end with ~iphone.xib
or ~ipad.xib
.
Note: It's case sensitive don't use iPad
or iPhone
.
Check that each xib
file has all outlets connected and has the correct fileowner set. If some are missing, iOS could decide not to use them and use the iPhone files instead.
For differentiating Images for iphone and ipad
Platform-specific modifiers—Use the modifiers ~iphone or ~ipad to specify images targeting a specific size of device.
Official document InfoPlistKeyReference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With