Different XIB files for iPhone 5 automatically - ios

I am updating my app to support the new iPhone 5.
I was wondering if there's any sort of way that you can create a different XIB file for the iPhone 5 that will load automatically, like when images with "#2x" in the end are loaded automatically when an iPhone 4 is used, without having to make any changes to the code itself.
Thanks!

As I know, there is no simple way to load correct xib for iPhone5 without extra code. However, i can suggest this simple class for detecting iPhone5. In addition, there also is a category for selecting correct image for iPhone5 here. You can do the same for initWithNibName:bundle: method.

Related

Can I use size classes in xib file in IOS 8.1?

My app is a universal app, i.e. the app is for iPhone_portrait and iPad_landscape.
I searched a lot about how to deal with iPhone and iPad, and I found that I can make my add adaptive using size classes, especially after IOS 8 size classes
my question is :
Is this solution is a the best one, even if the design wan't simple?
I have a lot of xib files in my app. Can I use size classes in this case? Or I need two xib one for iPhone, one for iPad?
thanks.
Yes you can use size class and AutoLayout. see the following screen shot there is tick mark on right side in File inspector.

iOS - Open a different Stroryboard based on the device size

I have created an app in Swift and I want it to be available in both iPhone and iPad, but I would like the iPad to have a couple different layout variables, such as bigger buttons and pictures. Using auto-layout or Size Classes with constraints wasn't working and not letting me put them where I want them, so I was wondering how to make it so that when I open the simulator with an iPad, it opens the storyboard with the different View Controller layouts. I made a duplicate storyboard so I have main.storyboard and the copy is mainiPad.storyboard for the iPad only. If this can be done, please let me know! Thanks!!
This Tutorial is the old way, when You simply add iPad suffix in the file name.
This Post is the new way, introduced in Xcode 6; You simply select the storyboard name for ipad and iphone family in application plist file.

Make an application work on both iPhone and iPad

I would like to make it so that my iPhone app also works on iPad.
If I run it using the iPad simulator it does work, but the app doesn't show up on the iPad app store, and looks really weird.
Is it possible to create another .xib file for the iPad? I know how to add a new iPad .xib file, yet I don't know how to actually change the RootViewController.xib to RootViewController_iPad.xib if the device being used is an iPad.
I already have code for finding out if the device is an iPad, and I don't want to use auto-layout, because I would like to add different things to the view if they are using an iPad (such as using different images).
I would like to make it so that my iOS applications look good on both iPhone and iPad, and have a separate .xib files for each. Is it possible to change the default .xib file from RootViewController to RootViewController_iPad?
In order to make an application work in both iPhone & iPad then need to follow below steps.
Before create an project please select universal in device section.
In application: didFinishLaunchingWithOptions: put a condition to check the device.
If the device is iPad then load the iPad screen and if the device is iPhone then load the iPhone screen.
Make sure follow the MVC pattern, So that it is easy to populate the data in both the screens.
#class has no effect on outlets or actions it only tells the compiler that there is a class with the name that follows, no information about properties, or methods is included.
If you want to have a xib for the iPad don't create a new class for it, just create a new xib and set the file's owner to be the same as the what owns iPhone xib. You then need to add a check in application: didFinishLaunchingWithOptions: to load the correct xib.
The best option though is to tell Xcode you want a universal app when you create the project.
The key point here is that it must be a UNIVERSAL application. Its a setting when you set the app up for the 1st time. You will end up with 2 UI's (story boards or xib files).
You will have to create 2 seperate UI's for ipad and iphone. You may be able to use the main class itself for most of the code but then you have to basically put code that says
if its iphone.....
if its ipad ......

Can I make one XIB/NIB that can be shared across iPhone and iPad UIs in a Universal App?

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
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.
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.

Add ipad interface to iphone app

I have been watching some of the solutions for this problem. There's any solution that not implies changing the code? I have seen solutions like put an if/else with the device type every time I load a ViewController. Theres no a way with xcode that this step is automaticaly done?
If you are using storyboards in the info.plist you can choose by configuration each storyboard, one for iPad and other for iPhone/iPod touch
If you are using xibs you'l need to change it programmatically using ifs and elses
I found a better method to include my iPad Xib in my project. I only have to add ~iPad at the end of the name of my xib. If I have myxib.xib I create a new xib named myxib~iPad.xib and when I run it on my ipad it takes automatically the correct file!

Resources