Reputation: 2684
The common practice I followed earlier during creating XIB files for universal applications was as follows:
I create the Xib file for both iPhone and iPad. Name them as XibFile.xib and XibFile~ipad.xib. For iPhone 4/4s and iPad3 I used retina images, where ever required. So that covered all my UI designs. And also my clients needed the iPhone5 screens in letterbox mode. I did not use the [email protected]. So life was going smooth at my end. But now when Apple decided to stop supporting Letterbox mode since May 1(read this article), I needed Xib level changes for iphone5 screens also. So for now I used auto resizing in the Xib file, and used vertical expansion for all my screens, and that solved most of my issues. Now please advice me the best practice in doing the XIB file creation, providing support to iphone5/4/4s and iPad.
1.) Design for iphone5, 4" screens and use auto resizing for iPhone 4/4s. This will not compromise in the clarity of the images I use.
2.) Create 2 different Xib files for iphone. One for the 4" iPhone5 and other for normal iPhone4/4s screens.
Please advice which is the best practice. Also please let me know, if there is some other way.
Upvotes: 2
Views: 759
Reputation: 45598
You only need to create multiple XIBs if the lay out is fundamentally different for the different devices.
If you can reuse the same XIB for both iPhone 4 and 5 with appropraite autoresizing behaviour, do so.
Upvotes: 1
Reputation: 3506
Take different xib and put this coding you can easily manage.
//Device Compatibility
#define g_IS_IPHONE ( [[[UIDevice currentDevice] model] isEqualToString:@"iPhone"] )
#define g_IS_IPOD ( [[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"] )
#define g_IS_IPAD ( [[[UIDevice currentDevice] model] isEqualToString:@"iPad"] )
#define g_IS_IPHONE_5_SCREEN [[UIScreen mainScreen] bounds].size.height >= 568.0f && [[UIScreen mainScreen] bounds].size.height < 1024.0f
#define g_IS_IPHONE_4_SCREEN [[UIScreen mainScreen] bounds].size.height >= 480.0f && [[UIScreen mainScreen] bounds].size.height < 568.0f
if(g_IS_IPHONE_5_SCREEN)
{
DashboardViewController* deshObj=[[DashboardViewController alloc] initWithNibName:@"DashboardViewController" bundle:nil];
}
else if(g_IS_IPHONE_4_SCREEN)
{
DashboardViewController* deshObj=[[DashboardViewController alloc] initWithNibName:@"DashboardViewController4" bundle:nil];
}
else if(g_IS_IPAD){
DashboardViewController* deshObj=[[DashboardViewController alloc] initWithNibName:@"DashboardViewControllerIpad" bundle:nil];
}
else{
DashboardViewController* deshObj=[[DashboardViewController alloc] initWithNibName:@"DashboardViewController" bundle:nil];
}
you can easily put your condition
Upvotes: 0
Reputation: 119031
Using auto resizing is a good solution, it keeps your interface definitions and code simple and minimal. There would probably be very few differences between the 4 & 5 XIB files.
The area you're likely to see issues using this method is where you have scroll views defined in the XIB where the content size is specified only in the XIB. In this case you'll need to add a bit of code to calculate the content size and possibly resize the content as autoresizing won't cover it.
Upvotes: 0
Reputation: 924
Best way would be to check for different models of iphone or ipad and do the needful accordingly. You can check iphone versions using the below code.
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) {
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width * scale, result.height * scale);
if(result.height == 960) {
NSLog(@"iPhone 4 Resolution");
resolution_number = 1;
}
if(result.height == 1136) {
NSLog(@"iPhone 5 Resolution");
}
}
else{
NSLog(@"Standard Resolution");
}
}
Upvotes: 0