Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode - How do I Detecting screen size of iPhone [closed]

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!

like image 296
Brad Conidaris Avatar asked Nov 28 '22 21:11

Brad Conidaris


1 Answers

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!!!!

like image 145
NiravPatel Avatar answered Dec 21 '22 20:12

NiravPatel