How to create iPad xib file in iPhone specific project - ios

I did a project few days back for iPhone but now i want to add iPad xib file into it. As features are enhancing. But the problem is that, at starting i selected an iPhone target for xib file not universal project.
So now i want to add xib for iPad's .
I created a new xib file for iPad but don't know how to load this on iPad instead of default xib file which is created for iPhone.
I have been checking a lot of other questions but didn't find any correct answer.Xcode 4 .xib Create iPad Version But its not working for me
I'm working on Xcode 5 and iOS 7.0.x

For automatic loading xib for iPad add ~ipad to the name of xib file.
For example:
If name of xib for iPhone version is CustomVC.xib
then for iPad version use CustomVC~ipad.xib.
When you create object of vc CustomVC *vc = [[CustomVC alloc] init]; iOS will automatically choose correct xib file depending on platform (iPhone or iPad) where application is run.

On the general tab for the target settings you'll find "Deployment Info"
Change "Devices" to "Universal" (You've probably already done this) The first time you do this it should ask you if you want to copy the iPhone storyboard to create an iPad storyboard. Choose the correct answer.
Select iPad from the tabs below devices.
Change "Main Interface" to your new storyboard.

Related

XCode does not recognize iPad storyboard

I have two storyboards Main and Main_iPad. My problem is that, in both of iphone and ipad devices, only Main storyboard gets selected and executed. What I did is:
iPad storyboard selection
iphone storyboard selection
I dont know its usage
So, whenever I change Universal from Main to Main_iPAd my it is working on iPad but crashes on iphone. But when I change it to Main, then it works both on iPad and iphone but, does not recognize the model inside Main_iPad. What can be problem?
I've had this same problem. My conclusion is that you can't configure this correctly by editing the target (as you are doing). You have to go directly into the Info.plist file and set it up there, by editing the "Main storyboard file base name" and "Main storyboard file base name (iPad)" entries.

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.

How to create xib both for iphone & ipad using xcode 6?

when I add a new file "Cocoa Touch Class" that I only could choose ipad "or" iphone 's xib. So how to create both ipad & iphone 's xib for the view class?
Add a new xib file. Connect it to your class. Name it with "~ipad" extension. For example if for iphone you have ViewController.xib, name it ViewController~ipad.xib for ipad. App will automatically pick the xib according to device.
if your application have 1 or more views but very less then i'll suggest you to work with [UIWindow sharedWindow] but if you have multiple view then in xcode 6 you have another option known as sizedClasses you'll just have to enable sizedClasses for your viewController
using interface Builder but remember, you'll have to use constraint to adjust your subviews accordingly.
Thanks

Universal app iPad to iPhone

I have created an Universal app. I have designed the app for iPad. But it doesn't work in iPhone. Will it work automatically or do i have to create all nibs separately for iPhone.
Of course it will not work automatically, if your design is for iPad only it will not work on the iPhone.
You will have to create separate XIBs for the iPad and iPhone, you can use the same viewController (.h and .m file) but seperate XIBx. Just add the device modifier to the file: MyViewController.xib and MyViewController~iphone.xib or MyViewController~ipad.xib.
Ofcourse it will not work for iPhone by itself. But its not difficult to add the support for iPhone.
Create a new StoryBoard for iPhone. Then open your iPad StoryBoard, the one you already created. Select all and copy. And then open iPhone StoryBoard and paste it in. All the controls and everything you have done in the iPad StoryBoard will be added to your iPhone StoryBoard.
After that you can do modifications in iPhone StoryBoard like remove or add some new controls etc.
Hope this helps!

Update iPad application to universal application

If I release to appStore application which is compatible with iPad only.
Can I release update to this application which will be universal (compatible with iPhone, iPod, iPad..)?
Do I need only to recreate my app or I must to do something more?
Yes you can, I have done it.
Depending on how you have made your app, xibs or Storyboards will determine how you do it.
for Storyboards
If going from iPhone to iPad:
Duplicate storyboard rename it: MainStoryboard_iPhone.storyboard (include .storyboard)
Inside xCode: right click on the new storyboard -> “open as” -> “Source Code”
Search for targetRuntime line near the top ="iOS.CocoaTouch.iPad"and change it to targetRuntime="iOS.CocoaTouch"
This will create an additional iPhone storyboard. Adjust your artwork/views in the new storyboard as necessary to fit the iPhone screens
Check in the summary screen that the deployment info Main Storyboard is set to the correct storyboards for iPhone and iPad respectively
Submit as an update.
If your using xibs you can duplicate and rename them ~iPad if going from iPhone to universal or ipad app, not sure about the other way around for xibs
No new bundle ID needed

Resources