Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8535027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:20:00+00:00 2026-06-11T10:20:00+00:00

I’ve just upgraded to Xcode 4.5 GM and found out that you can now

  • 0

I’ve just upgraded to Xcode 4.5 GM and found out that you can now apply the ‘4" Retina’ size to your view controller in the storyboard.

Now if I want to create an application that runs on both iPhone 4 and 5, of course I have to build every window twice, but I also have to detect whether the user has an iPhone with 3.5" or 4" screen and then apply the view.

How should I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:20:01+00:00Added an answer on June 11, 2026 at 10:20 am

    First of all, you shouldn’t rebuild all your views to fit a new screen, nor use different views for different screen sizes.

    Use the auto-resizing capabilities of iOS, so your views can adjust, and adapt any screen size.

    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.

    [ [ UIScreen mainScreen ] bounds ].size.height
    

    The iPhone 5’s screen has a height of 568.
    You can imagine a macro, to simplify all of this:

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

    The use of fabs with the epsilon is here to prevent precision errors, when comparing floating points, as pointed in the comments by H2CO3.

    So from now on you can use it in standard if/else statements:

    if( IS_IPHONE_5 )
    {}
    else
    {}
    

    Edit – Better detection

    As stated by some people, this does only detect a widescreen, not an actual iPhone 5.

    Next versions of the iPod touch will maybe also have such a screen, so we may use another set of macros.

    Let’s rename the original macro IS_WIDESCREEN:

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

    And let’s add model detection macros:

    #define IS_IPHONE ( [ [ [ UIDevice currentDevice ] model ] isEqualToString: @"iPhone" ] )
    #define IS_IPOD   ( [ [ [ UIDevice currentDevice ] model ] isEqualToString: @"iPod touch" ] )
    

    This way, we can ensure we have an iPhone model AND a widescreen, and we can redefine the IS_IPHONE_5 macro:

    #define IS_IPHONE_5 ( IS_IPHONE && IS_WIDESCREEN )
    

    Also note that, as stated by @LearnCocos2D, this macros won’t work if the application is not optimised for the iPhone 5 screen (missing the Default-568h@2x.png image), as the screen size will still be 320×480 in such a case.

    I don’t think this may be an issue, as I don’t see why we would want to detect an iPhone 5 in a non-optimized app.

    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.
    Note that dimensions of nativeBounds is measured in pixels, so for an iPhone 5 the height will be 1136 instead of 568.

    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 */
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.