Search code examples
iosviewuiviewcontrollertoggleiphone-5

Display different xib files based on iPhone screen size


I've made a few apps now that work on iPhone 5 and iPhone and it's really becoming a hassle to program and resize everything based on the frame.view.height so this time I made to views in my xib file, one with an iPhone 5 retina UIView and one with the regular UIView... now how do I display one if the user is using an iPhone 4- and the other if they are using an iPhone5+... I'm assuming it will be done somewhere in the app delegate.

I can detect wether or not the user is using an iPhone 5 by checking the superviews frame height in the ViewDidAppear (*It does NOT work in the ViewDidLoad)

But where do I go from there to choose which view I display... I have 1 view controller and both view's content in the xib file are hooked up to that view controlled. The views themselves are not hooked up... only one is with the default "*view" that comes with a blank Xcode project, I don't know how to add a second one.

Thanks!


Solution

  • You can test [UIScreen mainScreen].bounds.size.height instead of your views to accurately find the height of the screen. If it's 480 it's iPhone 4/4s, if it's 568 it's an iPhone 5 4 inch screen