Question

I'm sorry for my english.

In the app that i'm trying to develop in the first view i have a set of 4 images, one banner and one tab bar that i want to cover totally the screen size. For the 3.5-inch iPhones there isn't problem but the problems begin with 4-inch iPhone. At the moment i'm using autolayout and every image has a constraint to the top superview but i suppose that isn't the best solution to fix my problem in fact that causes a white clear space between images and tab bar in iphone 4-inch views.

To fix this problem, in your opinion, which is the best solution? Is possible to stretch the images and resize them to cover totally the screen? Or is better to have two different set of images that are loaded in according with the device screen size?

Another idea that i have is to use images with a right size for iphone 4-inch and when are displayed in a iphone 3.5-inch are partially covered like at the bottom of this example:

http://www.manuelragazzini.it/microfoni.jpg

Below i post an example of my situation and what that i'd like as result (in 3.5-inch there is also a navigation bar but is programmatically hide so the view is perfect)

http://www.manuelragazzini.it/domanda.jpg

Was it helpful?

Solution

What i think its better that you provide two seperate nib files for 3.5 and 4 inch display. Yes I know that this will increase your efforts but yes the code will be more managable in future. You just need to provide separate nibs.

You can make use of the following method to load nib dynamically each time for required dimension.

-(void)pushViewController:(UIViewController*)viewController withNib:(NSString*)nibName
{


 if(nibName){

    nibName=[self getNibNameForNib:nibName];

    viewController=[viewController initWithNibName:nibName bundle:nil];
    [self.navigationController pushViewController:viewController animated:YES];
}

}


-(NSString*)getNibNameForNib:(NSString *)nibName
{
NSString *newNibName=nil;

if([self isIphone5Retina4InchDisplay]){
    newNibName=[nibName stringByAppendingString:@"-568h"];
}

if(newNibName && [[NSBundle mainBundle] pathForResource:newNibName ofType:@"nib"] != nil)
{
    //if iphone 5 and nib is also present for that resolution.
    nibName=newNibName;
}

return nibName;
}

/**
 Method to get if device is 4 inch iphone 5 retina device or not.
 */
-(BOOL)isIphone5Retina4InchDisplay
{   

CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
    // code for 4-inch screen
    return YES;
} else {
    // code for 3.5-inch screen
    return NO;
  }
}

JUST NAME THE RETINA 4 INCH NIB NAME AS LoginViewController-568h.xib i.e. add -568h suffix. Use this pushViewController method each time to push a new view controller. You can write this method in your Base view controller.

OTHER TIPS

I'd go with 2 sets of image for your microphone example, just because if you want to have this whitespace between the tab and the mic, it's the way to go.

You could implement this by checking the iPhone Model in your code and thus loading corresponding image.

If you're low on diskspace (can't have multiple iPhone model images), then the resize method could do it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top