atomikpanda
atomikpanda

Reputation: 1886

Create two xibs, one for iPhone and one for iPad

How would I create device specific xibs? I made one for iPhone that is universal, but how can I use separate xib files?

Upvotes: 0

Views: 230

Answers (3)

pasawaya
pasawaya

Reputation: 11595

From the Apple Resource Programming Guide:

Note: If you are developing a Universal application for iOS, you can use the device-specific naming conventions to load the correct nib file for the underlying device automatically. For more information about how to name your nib files, see “iOS Supports Device-Specific Resources.”

In the "iOS Supports Device-Specific Resources" document, it says this:

To associate a resource file with a particular device, you add a custom modifier string to its filename. The inclusion of this modifier string yields filenames with the following format:

basename - device.filename_extension

The string represents the original name of the resource file. It also represents the name you use when accessing the file from your code. Similarly, the string is the standard filename extension used to identify the type of the file. The string is a case-sensitive string that can be one of the following values:

  • ipad - The resource should be loaded on iPad devices only.
  • iphone - The resource should be loaded on iPhone or iPod touch devices only. You can apply device modifiers to any type of resource file.

So if you wanted separate .xib files, you would include the iPad xib called "MyView-ipad.xib" and the iPhone xib called "MyView-iphone.xib".

Once you have these files included in your project, when you call this:

UIViewController *someViewController = [[someViewController alloc] initWithNibName:@"MyView" bundle:nil];

Depending on which device your application is running on, the correct xib file will be loaded.

Hope this helps!

Upvotes: 3

bkbeachlabs
bkbeachlabs

Reputation: 2171

If you have already created your project as an iPhone project you will need to change it to a universal app

Upvotes: 0

coneybeare
coneybeare

Reputation: 33101

This is the default setting when creating a new project. For a concrete example, I would create a blank project for iPhone and iPad and dig in.

Upvotes: 1

Related Questions