-->

Best way for creating universal native iPhone/iPad

2019-09-04 13:50发布

问题:

Which approach is good to create universal native application for iPhone/iPad:

1) Create separate NIB files for iphone and iPad versions and load the specific version by checking (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad).

2) Get the dimension of the main screen and frame the view accordingly

CGRect mainWindow = [[UIScreen mainScreen] bounds];
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, mainWindow.size.width, mainWindow.size.height)];

Please suggest if any other approach that I missed

Thanks, Ajay

回答1:

I am using the first approach, in many cases, at least for my own it is sufficient to set autoresizing masks. You have not said anything about this, but if your application will look pretty much the same (up-scaled layout) this works fine. In the cases I need another layout I have checked whether it is an iPad/iPhone and loaded the correct NIB, or used the GUI code in loadView based on the device.

From you example code with the webview you could use autoresizing masks and it would resize to the correct proportions when the frame changes.