IOS-create UIWindow, and ios create uiwindow

Source: Internet
Author: User

IOS-create UIWindow, and ios create uiwindow

After the iOS program is started, the first attempt to create the control is UIWindow. Then, create the view of the controller and add the view of the Controller to the UIWindow.

APPdelegate. m

-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {// Override point for customization after application launch. // window Notes: 1. do not be destroyed. Make a strong reference. 2. required window size // 1. create window object self. window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen]. bounds]; self. window. backgroundColor = [UIColor yellowColor]; // 2. create the root controller of the window and assign the value UIViewController * rootVc = [[UIViewController alloc] init]; rootVc. view. backgroundColor = [UIColor greenColor]; self. window. rootViewController = rootVc; // 3. display window [self. window makeKeyAndVisible]; return YES ;}
Both the keyboard and status bar are windows.
UITextField *text = [[UITextField alloc] init];[text becomeFirstResponder];[self.window addSubview:text];
Window Level UIWindowLevelNormalUIWindowLevelStatusBarUIWindowLevelAlert

Alert is the largest. You can add or subtract layers.

Load controller through storyboard
-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {// Override point for customization after application launch. // 1. create window self. window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen]. bounds]; // 2. load main. storyboard // name: storyboard name does not need to be suffixed with UIStoryboard * storyboard = [UIStoryboard storyboardWithName: @ "Main" bundle: nil]; // load the storyboard controller // The Controller pointed to by the default loading arrow // UIViewController * vc = [storyboard instantiateInitialViewController]; // load the Controller UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier: @ "blue"]; // sets the window's root controller self. window. rootViewController = vc; // 3. display window [self. window makeKeyAndVisible]; return YES ;}
Create a controller through xib

// Step for xib to attach a controller // xib must have a view to describe which view in the Controller // which describes the Controller view in xib, and must be connected // to establish a connection between the xib and the Controller, tell xib to describe the controller self. window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen]. bounds]; ViewController * vc = [[ViewController alloc] initWithNibName: @ "vc" bundle: nil]; self. window. rootViewController = vc; [self. window makeKeyAndVisible];
Load controller using loadview Method

Underlying implementation: determines whether a specified storyboard exists. If yes, the view of the Controller described in storyboard is created. If not, an empty view is created.

// Function: load the view of the controller. Call time: When the view of the controller is used for the first time, the call // BGView is the newly created object inherited from the UIView-(void) loadView {BGView * view = [[BGView alloc] initWithFrame: [UIScreen mainScreen]. bounds]; self. view = view; self. view. backgroundColor = [UIColor redColor];}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.