Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 298
Paresh Navadiya Avatar asked Dec 06 '12 11:12

Paresh Navadiya


1 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

like image 115
5 revs, 2 users 73% Avatar answered Sep 20 '22 06:09

5 revs, 2 users 73%