IOS通用應用程式
簡介
通用的應用程式是為iPhone和iPad在一個單一的二進位檔中設計的應用程式。這有助於代碼重用,並能夠幫助更快進行更新。
實例步驟
1、創建一個簡單的View based application(視圖應用程式)
2、在檔查看器的右邊,將檔ViewController.xib的檔案名稱更改為ViewController_iPhone.xib,如下所示

3、選擇"File -> New -> File... ",然後選擇User Interface,再選擇View,單擊下一步

4、選擇iPad作為設備,單擊下一步:

5、將該檔另存為ViewController_iPad.xib,然後選擇創建
6、在ViewController_iPhone.xib和ViewController_iPad.xibd的螢幕中心添加標籤
7、在ViewController_iPhone.xib中選擇identity inspector,設置custom class為ViewController

8、更新AppDelegate.m中的 application:DidFinishLaunching:withOptions方法
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];
// Override point for customization after application launch.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc]
initWithNibName:@"ViewController_iPhone" bundle:nil];
}
else{
self.viewController = [[ViewController alloc] initWithNibName:
@"ViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
9、在專案摘要中更新設備中為universal,如下所示:

輸出
運行該應用程式,我們會看到下麵的輸出

在iPad模擬器中運行應用程式,我們會得到下麵的輸出:

