iOS Development-72 sets the status bar in two ways, the program life cycle, and a better understanding of the relationships between several large classes (objects)

Source: Internet
Author: User

(1) 2 ways to set the status bar

--The first way is that we set in the controller, the system by default is given to the view controller to manage, so different view controllers can customize the different status bar as follows:

-(BOOL) prefersstatusbarhidden{}-(Uistatusbarstyle) preferredstatusbarstyle{}

--if we need to give UIApplication object Management (IOS6 before), you need the following settings:

Change the default settings in Info.plist first:


Then just use the following code:

-(void) Viewdidload {    //default is the Controller management status bar, different controllers can have different status bars    //We can set up application to manage the status bar, this management is unified    [uiapplication Sharedapplication].statusbarhidden=yes;    [UIApplication sharedapplication].statusbarstyle=uistatusbarstylelightcontent;    The following method can also animate    [[uiapplication sharedapplication] Setstatusbarhidden:yes withanimation: Uistatusbaranimationfade];    [[UIApplication sharedapplication] setstatusbarstyle:uistatusbarstylelightcontent Animated:YES];    [Super Viewdidload];}

(2) Program life cycle

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {    Viewcontroller *vc1=[[viewcontroller Alloc]init];    SELF.WINDOW.ROOTVIEWCONTROLLER=VC1;    Window is the first "view" to be created, and the views of the other controllers are visible to the user because they are displayed on the window. Do not use the following method is because the controller is a local variable, this function is finished, then the controller is eliminated, and at this time its view is still there, there is a wild pointer vulnerability.        So you can not just load the view, the entire controller needs to be loaded in, that is, using the above method//[self.window AddSubview:vc1.view];     /** * How does the program start?     * 1, first execute the main function * 2, in the Uiapplicationmain function: Create a UIApplication object, create a uiapplication delegate object * 3, delegate object start listening events * 3.1 For example, when the program starts loading, it calls the agent's didfinishlaunching ... Method * 3.2 In the method above, create the UIWindow, and then set the window Rootviewcontroller * 3.3 To display the window finally (naturally shows the Rootviewcontroller view     * * Above the third step is no storyboard, if there is storyboard, then how to show it? * 1, initialize a window * 2, initialize the storyboard point of view Controller * 3, finally the view controller is set to Window Rootviewcontroller, and then display window (equivalent to display the view controller View, which is the content of storyboard) */return YES;}

(3) The relationship between several major classes (objects)

UIApplication Object has an agent >>> is appdelegate, the agent inside the didfinishlaunching ... Method created UIWindow >>> This uiwindow has a rootviewcontroller that points to our common view controller Viewcontroller


iOS Development-72 sets the status bar in two ways, the program life cycle, and a better understanding of the relationships between several large classes (objects)

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.