PDA

View Full Version : XIB for both iPhone 3.5" and 4"?




Feltzem
Sep 13, 2012, 03:34 AM
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?



jnoxx
Sep 13, 2012, 05:23 AM
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:@"basisXib"]
and this will return the XIB name like basisXib_iPhone5 or basisXib_iPhone4, which you need to create obviously.

Duncan C
Sep 13, 2012, 06:37 PM
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?

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.