iOS universal app


Universal App for iOS


Introduction

Universal App is an application designed for iPhone and iPad in a single binary file. This facilitates code reuse and can help make updates faster.

Instance steps

1. Create a simple View based application (view application)

2. On the right side of the file viewer, copy the file ViewController.xib Change the name to ViewController_iPhone.xib, as shown below

UniversalAppInterfaceRename

3. Select "File -> New -> File...", then select User Interface, and then select View, click Next

NewIpadXib

4. Select iPad as the device, click Next:

UniversalAppSelectDeviceType

5. Save the file as ViewController_iPad.xib, then select Create

6. Add labels

7 to the center of the screen in ViewController_iPhone.xib and ViewController_iPad.xibd. Select the identity inspector in ViewController_iPhone.xib. Set the custom class to ViewController

UniversalAppSetClass

##8. Update the application:DidFinishLaunching:withOptions method in AppDelegate.m

- (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. Update the device in the project summary is universal, as shown below:

UniversalAppSetDevices

Output

Run the application, we will see the following output

UniversalAppiPhone_Output

Running the application in the iPad simulator, we will get the following output:

UniversalAppiPad_Output