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

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

Related

How can i create common xib for all ipads and iphones without creating seprate xibs for iphone and ipad? Not storyboard

Current xib's showing layout issues while switching between devices. I need single xibs which support all ios devices instead of using storyboard.
If you are using xcode 7.3 and above you can vary the constraints based on size class
https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/Size-ClassSpecificLayout.html
for xcode 8 there are some updation but underlying concept is size class , please check this
http://www.appcoda.com/auto-layout-guide/
https://makeapppie.com/2016/09/05/an-introduction-to-size-classes-for-xcode-8/

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 iPad xib file in iPhone specific project

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.

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!

IOS: app universal concepts

I'm starting a project that must be for iPhone and iPad...you can tell me that it's easy and that I can create an "Universal" project..it's right.
But I have a "stupid" question about a "stupid" problem.
In an universal project I have two .xib (iPhone and iPad) for a class and inside code I verify if I'm using the one or the other
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// The device is an iPad running iPhone 3.2 or later.
}
else
{
// The device is an iPhone or iPod touch.
}
ok?
But you know that in a single view of iPad I can show many views that an iPhone can show one at time.
At example I have two view with their classes:
FirstView.h-FirstView.m-FirstView_iPad.xib-FirstView_iPhone.xib
and
SecondView.h-SecondView.m-SecondView_iPad.xib-SecondView_iPhone.xib
For iPhone it's not a problem but for iPad? In a view in iPad I can put first and second viewcontroller, it's not easy to organize if I have two different classes for two viewcontrollers... Do you have a solution for this? Or the best solution is crate two separate project iPhone and iPad?
thanks
So yeah I always use one theViewController.h and one theViewController.m and I have a theViewController.xib for iPhone and a separate xib for iPad only. if you name the iPad xib ending with theViewController~ipad.xib the OS will automatically recognise the XIB. You will have to set the class of the theViewController~ipad.xib in Interface builder in the inspector area to the same class as your iphone xib i.e the class would be called theViewController then you can connect up what ever outlets you have defined in your .h and .m also the great thing about just naming the iPad xib to ending with ~ipad.xib when you push views you dont have to check the idom before pushing as the OS recognises the ~ipad.xib extension and pushes the correct view depending on device..hopefully this is helpful for you!

Resources