1

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

LittleFunny
  • 8,155
  • 15
  • 87
  • 198

6 Answers6

3

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

Community
  • 1
  • 1
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
1
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568)
   // 4-inch
else
   // 3.5-inch
sztembi
  • 223
  • 2
  • 10
  • Can i check the model number of the phone instead... http://support.apple.com/kb/HT3939?viewlocale=en_US&locale=en_US – LittleFunny Dec 10 '12 at 23:49
1
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

If the project doesn't include the Default-568h@2x.png 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)?

Community
  • 1
  • 1
JVC
  • 540
  • 3
  • 17
  • No, it doesn't. It centers the 3.5-inch interface on the screen of the iPhone 5. The pixels above and below are just black. – Anton Dec 10 '12 at 23:50
  • @Simon have you checked that on a real device? I saw different behaviour between device and simulator at least under the initial release of Xcode 4.5. – Tommy Dec 10 '12 at 23:50
  • From the code above that i posted, yes it has been checked on a real device. I wonder how to get a physical size of the phone instead of the screen size of the application used – LittleFunny Dec 11 '12 at 00:51
0

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.

Ken
  • 30,811
  • 34
  • 116
  • 155
0

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);
}
Anton
  • 3,998
  • 25
  • 40