Reputation: 4171
Are XIBs usable across platforms?
EG: I'm creating a Universal app. When creating a new XIB, Xcode wants me to pick a device family.
This bit of UI will be used in both versions of the app as-is and device family isn't really relevant (it's 200x250 pixels and can be displayed on both screens).
If I pick iPad for the device family, does this mean the xib will be invisible to the app when running on the iPhone?
If not are there any gotchas I should be aware of?
Edit: Specifically in this answer they imply that the device family is embedded in the NIB itself, possibly making it invisible on the "wrong" platform: https://stackoverflow.com/a/10459556/1461211
Upvotes: 1
Views: 2097
Reputation: 2660
yep they are are. But, the layout might be tricker when laying a single XIB for both phone and iPad.
If you are using iOS6+, use auto layout to create fully dynamic layouts that will work for both iPhone and iPad.
For layouts that just does not look right, you can create a ~iPad version of the XIB. So the iphone XIB is called 'DeskNoteDetails.xib' the iPad version would be named DeskNoteDetails~IPAD.xib' Now you can have to completely different layouts for the device. When the app needs to the load the DeskNoteDetailViewController view, the framework will determine which it should load the regular XIB or the ~IPAD.
So if you only have 1 XIB, the app will always load that 1 XIB for both devices. If you have a ~IPAD xib, the app will load the correct XIB for the device.
Upvotes: 5
Reputation: 4171
I have a possible answer, from the Resource Programming Guide (I swear I looked in the docs before posting the question!)
"On an iPhone or iPod touch device, the system loads the MyImage~iphone.png resource file, while on iPad, it loads the MyImage~ipad.png resource file. If a device-specific version of a resource is not found, the system falls back to looking for a resource with the original filename, which in the preceding example would be an image named MyImage.png."
Thus, it appears, that if there is no file with device specific extension in the file name it will load the same version on both platforms.
Upvotes: 0