XIB for both iPhone 3.5" and 4"?

Discussion in 'iOS Programming' started by Feltzem, Sep 13, 2012.

  1. Feltzem macrumors regular

    Sep 20, 2009
    I have installed the GM of Xcode 4.5 and there is an option in the .xib and storyboards Attributes Inspector (under 'Simulated Metrics') for choosing between 'Retina 3.5 Full Screen' and 'Retina 4 Full Screen'. If I choose Retina 4, adapt the interface and run it on my 3.5" device, the UI elements are in the positions for the 4" screen. Is there a way to use the same xib for a screen in the app and have it adapt depending on the screen size?
  2. jnoxx macrumors 65816


    Dec 29, 2010
    Aartselaar // Antwerp // Belgium
    Might be possible you just need to make 2 xibs, and make an Utility class that checks what device you are on, and it will return you the good string to use in the initWithNibname method. That's what I did for iPhone/iPad, instead of checking all the time before the initWithNibName. just do [Nibchecker nibWithName:mad:"basisXib"]
    and this will return the XIB name like basisXib_iPhone5 or basisXib_iPhone4, which you need to create obviously.
  3. Duncan C macrumors 6502a

    Duncan C

    Jan 21, 2008
    Northern Virginia
    I haven't started playing with the new screen-size yet, but in most cases it should be possible to make the content view anchor all 4 edges and resize it's content, and then set up struts and springs on the subviews so the layout adjusts to the different display sizes automatically.

    Failing that you can use the approach the other poster suggested, where at runtime you figure out which device you are running on and load a different XIB file for each. I will try to avoid that, though, because it is a pain to develop and maintain multiple XIB files with the same views and controls and set up all the outlets, actions, and attributes. I already do that for iPhone and iPad versions of my views, and supporting another XIB file for iPhone 5 would make it even worse.

Share This Page