4

I have two xibs, one for the iPhone 4 and one for the iPhone 5; 3.5 inch and 4 inch. I simply want to put some code that tells the app which to load. I have this code which is supposed to do the job:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone))
{
    CGSize result = [[UIScreen mainScreen] bounds].size;
    if(result.height == 480)
    {
    //Load 3.5 inch xib
    }
    if(result.height == 568)
    {
        //Load 4 inch xib
    }

I put it in the ViewController.M(is that where I put it?) and the build fails saying there is a parse issue expected identifier of "(" Can anyone help me with this simple fix? Thanks!

Brad Conidaris
  • 79
  • 1
  • 1
  • 3

4 Answers4

18

add below line in your prefix.pch file...this is the simplest way to check screen size, no need to make extra lines of code...

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

now whereever you want to check screen size , just make condition like below, and you can do whatever you want....

 if(IsIphone5)
{
    //your stuff
}
else
{  
  //your stuff
}

Happy Coding!!!!

NiravPatel
  • 3,260
  • 2
  • 21
  • 31
4

put this condition

if ((int)[[UIScreen mainScreen] bounds].size.height == 568)
{
    // This is iPhone 5 screen
} else {
    // This is iPhone 4/4s screen
}
D-eptdeveloper
  • 2,430
  • 1
  • 16
  • 30
2

remove extra ")" at the end from this line

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone))
Prashant Nikam
  • 2,253
  • 4
  • 17
  • 29
2

Try this remove last Bracket

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
      CGSize result = [[UIScreen mainScreen] bounds].size;
      if(result.height == 480)
      {
            //Load 3.5 inch xib
      }
      else if(result.height == 568)
       {
             //Load 4 inch xib
       }
}
guru
  • 2,727
  • 3
  • 27
  • 39