Create a single .xib for a universal application in Interface Builder? (IOS)

Sorry if this is a stupid question, but I did some search queries and searched SO and did not find anyone asking this exact question.

I have been developing iOS for some time, but I am completely new to Interface Builder. I want to know the following: is there a way to create only one .xib file and then use it for iPhone and iPad in a universal application?

It seems silly to me to create them separately; why is it twice as much as ever done in Interface Builder when I could do it once (with minor screen size settings) in the code?

Please let me know if I do not see / do not understand something here. As I said, I'm a complete newbie to Interface Builder :)

EDIT: In the past, I introduced games with a non-interface builder on the App Store, where the versions for the iPhone and iPad were identical, so I'm not interested in making the game look / differ on each device. I intend them to look exactly the same, besides some minor positioning changes due to the difference in aspect ratio.

+7
source share
4 answers

If you know what the resulting view based on auto-implementation will look like, you can really only use one .xib . It may come in handy if the view is only a kind of common component that automatically analyzes how you want it. However, if you want the presentation to look different on the iPad than on the iPhone, just use two .xib s. It can then be downloaded if necessary, for example, as an initializer, for example, such -init controllers:

 - (id)init { if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { self = [super initWithNibName:@"YourNibForPad" bundle:nil]; } else { self = [super initWithNibName:@"YourNibForPhone" bundle:nil]; } if (self) { /* initialize other ivars */ } return self; } 
+10
source

The main reason XIBs are separate files is because Apple believes that user interfaces designed for iPhones and iPod touch, and iPads should be adapted to each one accordingly. This is reflected in their iOS Application Programming Guide , which states the following:

For views, the main modification is to reverse engineer the layouts of the view to support a larger screen. Simple scaling of existing views may work, but often does not produce better results. Your new interface should use the available space and, if necessary, use new interface elements. This will likely lead to an interface that will be more natural for the user, and not just for the iPhone application on the big screen.

Although it may take time to maintain two XIBs for an effective virtual interface, I find it easier than using a single XIB, and then connecting most of your user interface elements to move them programmatically when that XIB is loaded. After all, with two XIBs, at least you can see what each user interface looks like, and then easily visualize.

As an aside, do not forget that the iOS 5 storyboards ( read about them here ), which greatly simplify the management of the view / view controller hierarchy, are easier.

+3
source

Try to name them.

MyCell.xib and MyCell ~ ipad.xib

then:

 [self.tableView registerNib: @"MyCell" forCellReuseIdentifier: @"MyUniqueIdentifier"]; 
+1
source

If you use IB, you need to create 2 separate xib files for iPhone and iPad. You need a separate iPad xib for your application to meet the requirements of the Apple iPad UI.

0
source

All Articles