iOS Universal Development – Use of Tilde Sign (~) in Xib File and Image Name for differentiation

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?

Answers


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


Need Your Help

Assembly version from command line?

dll visual-studio-2010 assemblies version

Is there a Microsoft tool to get the assembly version of a DLL file from a command line?

Laravel Tinker Not Working After Upgrading From 5.3 To 5.4

laravel

I recently upgrade Laravel 5.3 to Laravel 5.4. I had read the upgrade guide provided by the laravel, and everything looks good. Until I try to run the Laravel Tinker and it's not working. I already