Question

I currently have an iOS iPhone application.

What i want to do , is make it universal so that i can target the iPad too.

What i did , was go to the target and change the iOS application target , from iPhone to universal.

Now when i run the application on my iPad , it automatically resizes all the views for the iPad.

However there are some views , with background pictures that dont look so good , cause i need to use higher resolution pictures or in general i should change some things in the iPad version.

Where are the iPad .nib files??? I mean , i only see the iPhone ones. When i run it on my iphone , these files are used. When i run it on my iPad everything is resized correctly , but where the hell are these .nib files?

The tutorials (pretty old) that i read , suggested that when you target the iPad too , new .nib files should be created exact copies for the ipad. Why i dont see these files?

Was it helpful?

Solution

You can have iOS automatically load the right xib based on the extension, akin to how Retina graphics work. If your xib is named Awesome, and you want to convert it into having an iPhone and an iPad version (instead of being shared, rename it such that:

iPhone version:

Awesome~iphone

iPad version:

Awesome~ipad

Then, when you tell iOS to load Awesome, it'll pick which one to load based on the current platform automagically. No need for if statements in your code! You can still if you want, but it's not required.

Note: You might need to perform a clean after the rename! Sometimes some files stick around in the build when renamed.

OTHER TIPS

You will just need to make new .xib files and set them to the same class and you can init that viewController with a condition:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
     yourVC = [[YourViewController alloc] initWithNibName:"YourViewController_ipad" andBundle:nil];
}
else
{
    yourVC = [[YourViewController alloc] initWithNibName:"YourViewController" andBundle:nil];
}

Whenever possible you should try to use the same .xib but in a lot of cases it isn't possible to do that and look good so you just make a second. Xcode won't do it automatically for you.

Let's say that you have a class. We'll call it Two.

Here are the current files that make up the Two class.

Two.h
Two.m
Two.xib

Two.xib contains a UIView sized for the iPhone. In order to make a view sized for the iPad, you should create a new XIB file (name it Two_iPad.xib), connect the XIB to Two, resize the UIView in Two_iPad.xib for the iPad, and design accordingly.

When you are creating a new instance of Two, do the following.

Two *two;

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    //they are using an iPad

    two = [[Two alloc] initWithNibName:@"Two_iPad" bundle:nil];

} else {
    //they are using an iPhone/iPod Touch

    two = [[Two alloc] initWithNibName:@"Two" bundle:nil];

}

You are creating a new instance of Two; however, you are checking which device the user has, and using the corresponding XIB file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top