0

I am migrating my app to iphone app to iPhone 5 resolution. I have seen from other questions in stackoverflow stating this:

Example:

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

But it seems that, I need to add this code for all my images. Is there a simpler way? meaning a more generic way.

Thanks...

lakshmen
  • 28,346
  • 66
  • 178
  • 276
  • yes, I confirm you it is that simple. – holex Feb 14 '13 at 09:17
  • possible duplicate of [How to detect iPhone 5 (widescreen devices)?](http://stackoverflow.com/questions/12446990/how-to-detect-iphone-5-widescreen-devices) – trojanfoe Feb 14 '13 at 09:18
  • possible duplicate of [How to develop or migrate apps for iPhone 5 screen resolution?](http://stackoverflow.com/questions/12395200/how-to-develop-or-migrate-apps-for-iphone-5-screen-resolution) – Filip Radelic Feb 14 '13 at 09:26

5 Answers5

0

Create a category for UIImage class. Move this logic to UIImage class.

Now change the existing UIImage creation function with the one which you have created in the category.

Apurv
  • 17,116
  • 8
  • 51
  • 67
0

You can use AutoLayout if you are a registered Apple Developer I recommend the tutorials you can find from last year's WWDC.

JohannesRu
  • 160
  • 12
0

Check with writing this in prefix.h file

#define IPHONE5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

and whenever you want to check, Just check

if (IPHONE 5) {
     // Code for iPhone 5 Device
      enter code here
} else if (!IPHONE5) {
    // Code for 3.5 inch (iphone 4 nad less)
     enter code here
}
Regexident
  • 29,441
  • 10
  • 93
  • 100
swapnil
  • 25
  • 2
0

Build an app using iOS 6 as the Base SDK and use the Auto Layout feature to make screens that can scale for all type of screens. You'll need Xcode 4.5 to do this. Add a splash image named Default-568h@2x.png

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations

    switch (interfaceOrientation) {

        case UIInterfaceOrientationPortrait:
        case UIInterfaceOrientationPortraitUpsideDown:
            //[self ArrangeControllsFor_Protrate];
            [self performSelector:@selector(ArrangeControllsFor_Protrate) withObject:Nil afterDelay:0.005f];
            return YES;
            break;
        case UIInterfaceOrientationLandscapeLeft:
        case UIInterfaceOrientationLandscapeRight:
            [self performSelector:@selector(ArrangeControllsFor_LandScape) withObject:Nil afterDelay:0.005f];
            return YES;
            break;
    }
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{

    switch (toInterfaceOrientation){

        case UIInterfaceOrientationPortrait:
        case UIInterfaceOrientationPortraitUpsideDown:
            [self performSelector:@selector(ArrangeControllsFor_Protrate) withObject:Nil afterDelay:0.005f];
            break;
        case UIInterfaceOrientationLandscapeLeft:
        case UIInterfaceOrientationLandscapeRight:
            [self performSelector:@selector(ArrangeControllsFor_LandScape) withObject:Nil afterDelay:0.005f];
            break;
    }
}
-(NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskAll;
}
-(BOOL)shouldAutorotate{

    return YES;
}
-(void)ArrangeControllsFor_Protrate{

    [[UIApplication sharedApplication] setStatusBarHidden:NO];
    [self.view setBounds:CGRectMake(0, 0, 320,568)];
    [self.view setFrame:CGRectMake(0, 0, 320, 568)];
}

-(void)ArrangeControllsFor_LandScape{

    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    [self.view setBounds:CGRectMake(0, 0, 568, 320)];
    [self.view setFrame:CGRectMake(0, 0,  568, 320)];
}
- (void)viewWillAppear:(BOOL)animated{

    UIInterfaceOrientation statusBarOrientation = [[UIApplication sharedApplication] statusBarOrientation];
    if(UIInterfaceOrientationIsPortrait(statusBarOrientation))
    {
        [self ArrangeControllsFor_Protrate];
    }
    else
    {
        [self ArrangeControllsFor_LandScape];
    }
}
Ivan Ferić
  • 4,725
  • 11
  • 37
  • 47
Rahul
  • 134
  • 6
0
  1. First you have to create a launch image with dimensions 640 x 1136 and retina quality.
  2. Then name the image as Default-568h@2x.png and set it as launch image in your iphone application.
  3. Then you will have to set auto resizing mask.
  4. Create all the required images that you want to be compatible with iPhone 5 screen resolution.
  5. Run your app in your iPhone 5, everything should work as required.