iOS Hidden status bar

Source: Internet
Author: User

1. The entire project hides the status bar

Check hide status bar at targets->general->.

The entire project hides the status bar 2. A single interface hides the status bar, such as the sign-in registration page
    • 1. First 在info.plist里面View controller-based status bar appearance 设置为 NO .
  • 2. Add the following code to the Viewcontroller class that needs to regulate the status bar:
    //is hidden when entering-(void) Viewwillappear: (  bool) animated{[super viewwillappear:animated]; //hide =yes, show =no; Animation: Animation effect [[uiapplication sharedapplication] Setstatusbarhidden:yes withanimation:uistatusbaranimationnone";} //exit Display-(void) Viewwilldisappear: ( bool) animated{[super Viewwilldisappear:animated];//hidden =yes, showing =no; Animation: Animation effect [[uiapplication sharedapplication] Setstatusbarhidden:no withanimation:uistatusbaranimationnone];}      
3. Start the page to hide the status bar, enter the program after the normal display status bar
    • 1. First in Targets->General->勾选中Hide status bar or在info.plist里面 Status bar is initially hidden 设置为 YES
    • 2. Add code to APPDELEGATE.M
      -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {[application setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];}
IOS7, not only the application of the style has a certain change, the status bar changes relatively large, we can see the Uiviewcontroller status bar and navigation bar is basically a whole. So the method of hide/show state of Uiviewcontroller is not the same as other versions. In previous versions of IOS7, Hide/show was implemented with the following code
    1. [[UIApplication Sharedapplication] Setstatusbarhidden:yes (NO) withanimation:uistatusbaranimationslide];

This method is not successful by default in IOS7. To setstatusbarhidden:withanimation: Declaration of the header file to see, more than a note://Setting Statusbarhidden does nothing if your application is using The default uiviewcontroller-based status bar system. Now in IOS7, the appearance of the status bar depends on Uiviewcontroller, which means that the status bar varies with uiviewcontroller. In this default way, the global approach to setstatusbarhidden:withanimation: is not feasible.

Google found that there are two ways to solve the problem now:

If you are simply hiding the status bar, then by default, you only need to re-implement two new methods

    1. -(Uistatusbarstyle) Preferredstatusbarstyle
    2. {
    3. return uistatusbarstylelightcontent;
    4. //uistatusbarstyledefault = 0 Black text, used when light background
    5. //uistatusbarstylelightcontent = 1 white text, used when dark background
    6. }
    7. -(BOOL) Prefersstatusbarhidden
    8. {
    9. return NO; //Return no indicates to be displayed, return yes will hiden
    10. }


The previous callback method returns the style when the status bar is displayed, and the following callback controls whether the status bar is displayed.

Calling the following line of code will trigger the callback above

    1. [Self setneedsstatusbarappearanceupdate];

If you want to have a little animation between hiden/show, use the following code:

    1. [UIView animatewithduration:0.5 animations:^{
    2. [Self setneedsstatusbarappearanceupdate];
    3. }];

or call the following code:

    1. [[UIApplication sharedapplication] Setstatusbarhidden:yes withanimation:uistatusbaranimationslide];

Another way is to add key:uiviewcontrollerbasedstatusbarappearance to the Infor.plist and set its value to No, which tells the system that the status Bar does not depend on Uiviewcontroller. This allows you to hiden the status bar using the above method.

In setting these, we will still find some problems, that is, although the status bar is not, but instead of a black area, so we also need to adjust the Uiviewcontroller view, the code is:

-(void) Viewdidlayoutsubviews

    1. {
    2. CGRect viewbounds = self.view.bounds;
    3. CGFloat topbaroffset = 20.0;
    4. VIEWBOUNDS.ORIGIN.Y =-topbaroffset;
    5. Self.view.bounds = Viewbounds;
    6. [[UIApplication sharedapplication] setstatusbarstyle:uistatusbarstylelightcontent]; //for status bar style
    7. }

iOS Hidden status bar

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.