當前位置:
首頁 > 知識 > IOS通用應用程序

IOS通用應用程序

簡介

通用的應用程序是為iPhone和iPad在一個單一的二進位文件中設計的應用程序。這有助於代碼重用,並能夠幫助更快進行更新。

實例步驟

1、創建一個簡單的View based application(視圖應用程序)

2、在文件查看器的右邊,將文件ViewController.xib的文件名稱更改為ViewController_iPhone.xib,如下所示

IOS通用應用程序

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

IOS通用應用程序

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

IOS通用應用程序

5、將該文件另存為ViewController_iPad.xib,然後選擇創建

6、在ViewController_iPhone.xib和ViewController_iPad.xibd的屏幕中心添加標籤

7、在ViewController_iPhone.xib中選擇identity inspector,設置custom class為ViewController

IOS通用應用程序

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,如下所示:

IOS通用應用程序

輸出

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

IOS通用應用程序

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

IOS通用應用程序

喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 程序員小新人學習 的精彩文章:

什麼是UI元素?
IOS加速度感測器(accelerometer)
iOS程序編程
iOS 程序簡介

TAG:程序員小新人學習 |