iOS - Open a different Stroryboard based on the device size - ios

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.

Related

porting iPad app to iPhone using one storyboard with one storyboard

i am able to make my iPad app running on iPhone but the iPhone screens doesnt fit all the content in. For example my table view main text is hidden, the buttons are very much spaced from the border. I understand the spacing given in my storyboard files in too big for iPhone screen.
I want to make my app work for iPhone with very minimal changes. I dont want to create a new storyboard and rewrite everything. Please suggest a good way.
Thanks in advance.
You need to make the app Universal, make a single storyboard the main storyboard in both target's project settings and use Autolayout to position your UI elements respective of the device. Look into Size classes to keep your design responsive.

Using iPad and iPhone storyboards in Xcode

I have created an app with a storyboard in Xcode and I now want to create an iPad version. I successfully created an iPad storyboard, but it currently runs with the code from the iPhone version.
The issue I am having is that the code for the iPhone is still running with the iPad storyboard. I would like to duplicate the iPhone code and adjust it for the iPad.storyboard, but I am not sure how to do that. Thanks.
I took a screenshot for you:
So switch the tabs and assign the appropriate storyboard. and make sure it is set to universal.
If I understand your problem, you now have two storyboards, one for iPhone and one for iPad, which are both working properly, but you want to modify part of the code just for the iPad version.
You should duplicate the classes you want to edit for the iPad version of your app and assign those new classes to the corresponding ViewControllers of the iPad storyboard.
Of course, you are still making a single, universal app.

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

Xcode storyboard: Why does the iPad storyboard show iPhone sized views?

I have a universal app that uses storyboards. There is an iPhone storyboard and an iPad storyboard. However, in interface builder, the viewcontrollers for the iPad storyboard are still sized for the iPhone. How do I get the iPad storyboard to show iPad sized view controllers?
I realize that the view controller display in interface builder is design-time-only eye-candy, but having iPhone sized VCs makes it really hard to lay out the UI correctly.
After some digging through the storyboard source code, it turns out that the iPad storyboard was copied from the iPhone storyboard. So, the question really became how do I convert an iPhone storyboard into an iPad storyboard?
The answer is surprisingly simple. I ran across this SO answer -- to convert an iPhone storyboard to an iPad storyboard, do the following:
From Xcode, right-click on the storyboard and choose Open As ->
Source code
Search for targetRuntime="iOS.CocoaTouch"and change it to targetRuntime="iOS.CocoaTouch.iPad"
Right-click on the storyboard again and choose Open As -> iOS Storyboard
The storyboard will now show all views in the correct size.
When you first create a storyboard you select a Device Family (iPhone or iPad) that the storyboard is targeted for. I don't know of a way to change the device family once the storyboard has already been created.
However, to solve your problem I recommend the following:
Create a new storyboard by going to: New -> File -> User Interface -> Storyboard (Be sure to select Device Family = iPad when choosing the options.)
Go to your old storyboard, select and copy everything by pressing Command-A, Command-C. Then go to your and paste everything by pressing Command-V. Your view controllers will now be iPad-sized.
You can then delete the old storyboard and rename your new storyboard to whatever the old name was.
This answer is not a solution, but will help to get one of the reasons why such things happen.
The issue occurs when you try to disable:
"Use Auto Layout"
When you uncheck it, the popup window appears. There is select:
"Keep size class data for: iPhone", by default is selected iPhone (no matter which iPad or iPhone project you created).
If you will not mention on it, your storyboard will be auto converted to iPhone sizes.
Do not forget to choose right device.
I used the suggested answer to convert an iPhone storyboard to an iPad storyboard and it worked great for most of my views. However, I realized that one of the views was still iPhone storyboard sized. The reason was because I had locked All Properties of one background image (because I did not want to accidentally move it). Removing the lock turned the view back into iPad sized. This might help someone stuck on this.
Make sure you set the right Storyboard in Target > General. This kinda stuff makes me headache for 3 hours before i realise i set the same storyboard for iPhone as my iPad storyboard.
In my universal app, I was using SpriteKit for the main viewcontroller. The SKScene.scaleMode was set to aspectFill. When run in the iPad simulator, the app started up iPhone mode. Solution was to set scaleMode = .resizeFill.
For me i have found it more easy by changing the view controller presentation to Full Screen rather than Automatic, I use Xcode 12.1

converting story board from iphone to ipad

I have a storyboard for my iphone version of my app and I want to have the same storyboard for my ipad version (only bigger). My story board only has text and buttons is there anyway I can just convert the whole thing and increase the size by 2, or do have to resize everything manually?
You really need to do more than just resize you know. iPad users don't generally enjoy running iPhone apps at double size on the iPad and it sounds like that's what you're proposing to do.
In your storyboard you can drag and drop from your iPhone screens to iPad to get all of the elements into the iPad storyboard. Then maybe you will tweak a bit to make it more iPad friendly.
As far as I know, you will need to create a new storyboard and set that as the storyboard for iPad (app settings). You will then need to create the content manually (you can copy and paste the objects and use the existing controller classes though (will need to wire up the objects).

Resources