Download another xib for iPhone 5

My applications have additional features for iPhone 5, and I created a separate class with .xib for it. I would like to determine the height of the screen (unless it is possible to get the device identifier / model) and load another view controller accordingly. I tried this:

- (IBAction)select:(id)sender { CGRect screenRect = [[UIScreen mainScreen] bounds]; CGFloat screenWidth = screenRect.size.width; CGFloat screenHeight = screenRect.size.height; if (screenHeight == 960) { Selection *selectView =[[Selection alloc] initWithNibName:nil bundle:nil]; selectView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; [self presentModalViewController:selectView animated:YES]; } else { Selection_5 *selectView =[[Selection_5 alloc] initWithNibName:nil bundle:nil]; selectView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; [self presentModalViewController:selectView animated:YES]; } } 

Choice and Choice_5 are two different classes, each of which is different from xib for the user interface.

+8
ios objective-c iphone xcode ipad
source share
4 answers

try http://github.com/erica/uidevice-extension/

 [[UIDevice currentDevice] platformType] // ex: UIDevice4GiPhone [[UIDevice currentDevice] platformString] // ex: @"iPhone 4G" 

or you can just look at screenHeight as:

 float screenHeight = [UIScreen mainScreen].bounds.size.height; 

for height iPhone 5 is 568

and maybe you use a shell to install nib if you boot using .xib, for example:

 [[Selection alloc] initWithNibName:@"here_is_nibname" bundle:nil]; 
+5
source share

Firstly, you do not want to check the type of device. What will happen to the new touches of the iPod (which have the same screen size) or next year's iPhone.

But I think the problem is that you are checking the screen size based on the actual number of pixels that - oddly - are not what you want. Remember that on the retina screen everything "doubles." In the user interface, you (mostly) use the β€œnormal” size for everything, which in this case is half the number of pixels.

In short: check the screen height is 480 (normal) or 568 (iPhone 5).

+8
source share

In my application, I need to download the .XIB file for iPhone, iPhone5 / iPod Touch and iPad, for this is the code that I use:

 // If Iphone/iPod Touch if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { // If iPhone 5 or new iPod Touch if([UIScreen mainScreen].bounds.size.height == 568){ VCDadosViewController *extratoVC = [[VCDadosViewController alloc] initWithNibName:@"VCDadosViewControllerExt" bundle:nil]; ... } else{ // Regular iPhone VCDadosViewController *extratoVC = [[VCDadosViewController alloc] initWithNibName:@"VCDadosViewController" bundle:nil]; ... } // If iPad } else { VCDadosViewController *extratoVC = [[VCDadosViewController alloc] initWithNibName:@"VCDadosViewControllerPad" bundle:nil]; ... } 

Hope this helps someone who needs it :)

+5
source share

If you have this naming convention

 VGArticlePage~ipad.xib VGArticlePage~iphone.xib VGArticlePage~iphone_ext.xib 

Then you can do it as follows:

 #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) #define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) #define IS_IPHONE_5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0f) - (NSString *)nibNameForClass:(Class)class { if(IS_IPHONE && IS_IPHONE_5) { return [NSString stringWithFormat:@"%@%@", NSStringFromClass(class), @"~iphone_ext"]; } else if(IS_IPHONE) { return [NSString stringWithFormat:@"%@%@", NSStringFromClass(class), @"~iphone"]; } else { return [NSString stringWithFormat:@"%@%@", NSStringFromClass(class), @"~ipad"]; } } 
+3
source share

All Articles