Skip to main content
updated links
Source Link
Cœur
  • 39k
  • 25
  • 207
  • 282

That's not very hard, read some documentationsome documentation about that. It will save you a lot of time.

iOS 6 also offers new features about this, but this is still under NDA at the moment.
Be sure to read the API changelogiOS 6 API changelog on Apple Developer website, if you can access to it.

Edit: As iOS 6 is now out,
And check the new iOS 6 AutoLayoutAutoLayout capabilities.

That said, if you really need to detect the iPhone 5, you can simply rely on the screen sizescreen size.

And obviously, if you need to detect an iPhone 6 or 6 Plus, use the corresponding screen sizes.

Final note

Comments and suggestions have been incorporated in this post.
Thanks to everybody.

That's not very hard, read some documentation about that. It will save you a lot of time.

iOS 6 also offers new features about this, but this is still under NDA at the moment.
Be sure to read the API changelog on Apple Developer website, if you can access to it.

Edit: As iOS 6 is now out, check the new AutoLayout capabilities.

That said, if you really need to detect the iPhone 5, you can simply rely on the screen size.

And obviously, if you need to detect an iPhone 6 or 6 Plus, use the corresponding screen sizes.

Final note

Comments and suggestions have been incorporated in this post.
Thanks to everybody.

That's not very hard, read some documentation about that. It will save you a lot of time.

iOS 6 also offers new features about this.
Be sure to read the iOS 6 API changelog on Apple Developer website.
And check the new iOS 6 AutoLayout capabilities.

That said, if you really need to detect the iPhone 5, you can simply rely on the screen size.

And obviously, if you need to detect an iPhone 6 or 6 Plus, use the corresponding screen sizes.

added 737 characters in body
Source Link
Macmade
  • 54.3k
  • 14
  • 114
  • 127

In order to fix this, you can simply use the new nativeBounds property, instead of bounds, as it won't change with the orientation, and as it's based on a portrait-up mode.
Note that dimensions of nativeBounds is measured in pixels, so for an iPhone 5 the height will be 1136 instead of 568.

You can adapt the previous macros the following way:

#define IS_WIDESCREEN_IOS7 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON ) #define IS_WIDESCREEN_IOS8 ( fabs( ( double )[ [ UIScreen mainScreen ] nativeBounds ].size.height - ( double )1136 ) < DBL_EPSILON ) #define IS_WIDESCREEN ( ( [ [ UIScreen mainScreen ] respondsToSelector: @selector( nativeBounds ) ] ) ? IS_WIDESCREEN_IOS8 : IS_WIDESCREEN_IOS7 ) 

And obviously, if you need to detect an iPhone 6 or 6 Plus, use the corresponding screen sizes.

In order to fix this, you can simply use the new nativeBounds property, instead of bounds, as it won't change with the orientation, and as it's based on a portrait-up mode.

In order to fix this, you can simply use the new nativeBounds property, instead of bounds, as it won't change with the orientation, and as it's based on a portrait-up mode.
Note that dimensions of nativeBounds is measured in pixels, so for an iPhone 5 the height will be 1136 instead of 568.

You can adapt the previous macros the following way:

#define IS_WIDESCREEN_IOS7 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON ) #define IS_WIDESCREEN_IOS8 ( fabs( ( double )[ [ UIScreen mainScreen ] nativeBounds ].size.height - ( double )1136 ) < DBL_EPSILON ) #define IS_WIDESCREEN ( ( [ [ UIScreen mainScreen ] respondsToSelector: @selector( nativeBounds ) ] ) ? IS_WIDESCREEN_IOS8 : IS_WIDESCREEN_IOS7 ) 

And obviously, if you need to detect an iPhone 6 or 6 Plus, use the corresponding screen sizes.

added 737 characters in body
Source Link
Macmade
  • 54.3k
  • 14
  • 114
  • 127

IMPORTANT - iOS 8 support

On iOS 8, the bounds property of the UIScreen class now reflects the device orientation.
So obviously, the previous code won't work out of the box.

In order to fix this, you can simply use the new nativeBounds property, instead of bounds, as it won't change with the orientation, and as it's based on a portrait-up mode.

If you're also targeting iOS 7 or lower, be sure to use feature detection, as calling nativeBounds prior to iOS 8 will crash your app:

if( [ [ UIScreen mainScreen ] respondsToSelector: @selector( nativeBounds ) ] ) { /* Detect using nativeBounds - iOS 8 and greater */ } else { /* Detect using bounds - iOS 7 and lower */ } 

Final note

Final note

IMPORTANT - iOS 8 support

On iOS 8, the bounds property of the UIScreen class now reflects the device orientation.
So obviously, the previous code won't work out of the box.

In order to fix this, you can simply use the new nativeBounds property, instead of bounds, as it won't change with the orientation, and as it's based on a portrait-up mode.

If you're also targeting iOS 7 or lower, be sure to use feature detection, as calling nativeBounds prior to iOS 8 will crash your app:

if( [ [ UIScreen mainScreen ] respondsToSelector: @selector( nativeBounds ) ] ) { /* Detect using nativeBounds - iOS 8 and greater */ } else { /* Detect using bounds - iOS 7 and lower */ } 

Final note

added 244 characters in body
Source Link
Macmade
  • 54.3k
  • 14
  • 114
  • 127
Loading
added 806 characters in body
Source Link
Macmade
  • 54.3k
  • 14
  • 114
  • 127
Loading
added 806 characters in body
Source Link
Macmade
  • 54.3k
  • 14
  • 114
  • 127
Loading
added 469 characters in body
Source Link
Macmade
  • 54.3k
  • 14
  • 114
  • 127
Loading
added 166 characters in body
Source Link
Macmade
  • 54.3k
  • 14
  • 114
  • 127
Loading
Source Link
Macmade
  • 54.3k
  • 14
  • 114
  • 127
Loading