18

Possible Duplicate:
How to detect iPhone 5 (widescreen devices)?

I am trying to add a new view to an existing ios4 project to handle the new iphone5 screen size.

However I dont have an iphone here to test on and the code I am using to test the screen size isnt working, just wondering if there is another way of detecting the device type??

NSLog(@"%f", [ [ UIScreen mainScreen ] bounds ].size.height);

if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
    if([UIScreen mainScreen].bounds.size.height == 568.0)
    {
        //move to your iphone5 storyboard
        [self changeView:splashScreenBIGV viewH:splashScreenH animLength:SCREEN_CHANGE_ANIM_LENGTH];
   }
    else{
        //move to your iphone4s storyboard
        [self changeView:splashScreenV viewH:splashScreenH animLength:SCREEN_CHANGE_ANIM_LENGTH];            
    }
}
Community
  • 1
  • 1
hanimal_p
  • 303
  • 1
  • 3
  • 13
  • 1
    Try [an earlier answer to this question](http://stackoverflow.com/questions/12446990/how-to-detect-iphone-5-widescreen-devices). – Richard Altenburg - Brainchild Sep 26 '12 at 15:24
  • Ditto @RichardAltenburg-Brainchild - the reality of life is sometimes you need a quick fix. Moving to the constraint layout system is the long term correct approach but will take you some time if you have many views. – David H Sep 26 '12 at 18:30
  • Using my post here the optimization code for universal app iPhone 3Gs/4s/5 and iPad http://stackoverflow.com/questions/12395200/how-to-develop-or-migrate-apps-for-iphone-5-screen-resolution/17379460#17379460 – BlackSheep Sep 15 '13 at 21:50

2 Answers2

60

For my universal app, Forex App, I'm simply using the screen height detection concept like so:

CGSize screenSize = [[UIScreen mainScreen] bounds].size;

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    if (screenSize.height > 480.0f) {
        /*Do iPhone 5 stuff here.*/
    } else {
        /*Do iPhone Classic stuff here.*/
    }
} else {
    /*Do iPad stuff here.*/
}
DataPriest
  • 1,129
  • 8
  • 8
0

Answer is here. Basically, you don't. Use the new constraint layout system in iOS 6. You'll be chasing your tail if you have to rev your layout for every new device with a different screen size/resolution.

Community
  • 1
  • 1
rsswtmr
  • 1,776
  • 5
  • 16
  • 26
  • ok, I get what you are saying, I dont want to create new xib files for every screen that I have. So do I recreate all the screens as iphone5 screens? will it just shrink them for the older devices? – hanimal_p Sep 26 '12 at 15:39
  • The OP also said an existing iOS 4 project. maybe he doesn't want or need to go to iOS 6 yet – wuf810 Apr 17 '13 at 13:04