OC通用应用程序
通用应用程序是为iPhone和iPad设计的单个二进制文件中的应用程序。通用应用程序允许代码重用和快速更新。
涉及步骤
步骤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.xib 中添加标签。
步骤7- 在 ViewController_iPad.xib 中,选择身份检查器,然后将自定义类设置为 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; }

运行应用程序时,将获得以下输出-

在iPad模拟器中运行应用程序时,将获得以下输出-
祝学习愉快! (发现内容有误?请选中要编辑的内容 -> 右键 -> 修改 -> 提交!帮助我们改进教程质量)
精选教程推荐
👇 以下精选教程可能对您有帮助,拓展您的技术视野
暂无学习笔记,成为第一个分享的人吧!
您的笔记将帮助成千上万的学习者