1

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?

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Kitsune , thats what i was talking about in my comment on rooster117 answer.
1

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.

5 Comments

so for the .nib files that i just use a table view for example its not necessary to create a new one , but for the ones that need changes i add this in my code and create another nib? But why i ve seen projects with 2 different .xib files like ViewController_iphone.nib and ViewController_ipad.nib and absolutely nothing on code "telling" the app which one to use but in the end when you run on iphone is the correct one and when you run for ipad again is the correct one? How do they do that?
@d0nparalias This is specified in the `AppDelegate. The same code is there.
If you check Kitsune answer , thats what i am talking about , no need to write any code.
Yeah that's true I kind of forgot about that. It would be even better if you could just use one .xib and do checks for the device you are on and switch out some UI components assuming it can be done like that. Avoiding multiple versions of .xib's is always good
@rooster117 You could add multiple views to the class XIB, and then add view_iPad as an object of the class (you would have two views: self.view for iPhone and self.view_iPad for iPad.
1

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.

Comments