NMunro
NMunro

Reputation: 1290

Xib for iPhone and iPad

I have a Xib for iPhone and I need a similar view for iPad, only iPad size.

What is the best way of doing this? Can you put both views in the same Xib and somehow specify which one is shown?

Or do I need to be make 2 Xib files and 2 classes?

Upvotes: 4

Views: 3768

Answers (3)

Vineesh TP
Vineesh TP

Reputation: 7943

If you want both iPhone and ipad Create Universal App. Create only One XIB and create all controls only once not need to do it separately. Draw the frame in coding. ie, Create frame separate for both iphone and ipad.

Upvotes: 1

NMunro
NMunro

Reputation: 1290

I ended up using 1 class. I set the file owner of both XIB files to this same class.

I just used the name of the XIB file

So I have 2 xibFiles, iPadXib.xib and iPhoneXib.xib

NSString *nibFileName = (iPadVersion) ? @"iPadXib" : @"iPhoneXib";

ViewControllerName *vc = [[ViewControllerName alloc] initWithNibName:nibFileName bundle:nil];

Upvotes: 4

Rui Peres
Rui Peres

Reputation: 25907

Or do I need to be make 2 Xib files and 2 classes?

Actually, use three classes and 2 xibs. Like this:

  1. MyClass
  2. MyClass_iPhone: MyClass
  3. MyClass_iPad: MyClass

And the two xibs. It gives you much more flexibility. Keep the common logic on the MyClass, and sub-class the other two for the iPhone and iPad Version.

Upvotes: 2

Related Questions