通用应用程序是为iPhone和iPad设计的单个二进制文件中的应用程序。通用应用程序允许代码重用和快速更新。
步骤1 - 创建一个简单的基于视图的应用程序。
步骤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 。
链接:https://www.learnfk.comhttps://www.learnfk.com/ios/ios-universal-applications.html
来源:LearnFk无涯教程网
步骤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模拟器中运行应用程序时,将获得以下输出-
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)