Xcode - How to make a universal app

2019-09-08 04:55发布

问题:

I have an iPhone app and I want to make it universal, but I don't know how to go about doing this, at least properly anyway. Earlier I tried the "upgrade current target to iPad" but it didn't work properly, but luckily I saved a backup from just before trying it.

Anyway, can anyone advise me on how to do this?

回答1:

Create a new MainWindow_iPad.xib file targeted to iPad. Open the app's info.plist file. Add a new key for (something like) Main Nib Name(iPad). (Don't worry, Xcode will give you autocomplete options) Set it to this new .xib file. Now, when the app boots on an iPad, it'll load the new .xib. You can now write your code as normal.



回答2:

if ([[UIDevice currentDevice] userInterfaceIdiom]==UIUserInterfaceIdiomPhone) {
} else {
  //...
}