1
votes

I am wondering how i can detect using the screen size is iPhone 5. My application at the moment using 3.5 inch interface on a iPhone 5 so when I used the code

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

This gave me 400 instead of 568 height of the screen size. Is that because I am using 3.5 inch interface on a iPhone 5. I know i need to change the layout of the application but due to our time constraint I wanted to keep it that way.

Or Do I need to get the scale factor to get the real pixel

CGFloat screenScale = [[UIScreen mainScreen] scale];

Please help...

6

6 Answers

3
votes

you can easly detect iphone, iphone5 and iPad with below condition:-

 if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone)
 {
     if ([[UIScreen mainScreen] bounds].size.height == 568)
     {


     }
     else
     {
         //iphone 3.5 inch screen
     }
 }
 else
 {
        //[ipad]
 }

just visit my answer at this Detect device type

1
votes
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568)
   // 4-inch
else
   // 3.5-inch
1
votes
instead of find hight you have to use following code to find your device is iPhone 5 or below iphone 5.

#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
-(void)ViewDidLoad
{
   if(IS_IPHONE_5)
   {
      //code of iphone 5
   }
   else
  {
      //code of below iphone 5
  }
}
0
votes

If the project doesn't include the [email protected] with the new Default image, the iPhone 5 will report a regular 480x320 screen size.

Read this thread How to detect iPhone 5 (widescreen devices)?

0
votes

A layout should be able to adapt to this without checking for the device type, which will break as soon as Apple decides to change its form factor again.

Use Autosizing (distinct from Autolayout, but all the better if this is available to you), and where this doesn't suffice subclass UIView and override -layoutSubviews, use 9-patches etc. Do this and I see no real need to know whether the device is either an iPhone 4 or an iPhone 5.

0
votes

First, until you specify a loading image for an iPhone 5 in your app, it will run like an iPhone 4 and return { 320, 480 } when you call [[UIScreen mainScreen] bounds].size

Second, you should use bounds:

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

You may also want to account for the status bar height:

CGFloat statusBarHeight = ([UIApplication sharedApplication].statusBarHidden ? 0.0f : [UIApplication sharedApplication].statusBarFrame.size.height);

If you're getting the width of the screen dependent on the current orientation (portrait or landscape), you should flip the width and height returned by the bounds function.

if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
    screenSize = CGSizeMake(screenSize.height, screenSize.width);
}