Status Bar Summary

Source: Internet
Author: User

1. Style

There are two styles of StatusBar:

        • Uistatusbarstyledefault:

        • Uistatusbarstylelightcontent

Change the status bar text color method:

1) Set the controller settings of the storyboard directly:

2) code settings, overloading in Uiviewcontroller:

-(Uistatusbarstyle) Preferredstatusbarstyle
{
Returnuistatusbarstylelightcontent;
}

This method cannot be called directly, and is called where the style needs to be changed: [self setneedsstatusbarappearanceupdate]

Example:

-(void) Viewwillappear: (BOOL) animated
{
[Self setneedsstatusbarappearanceupdate];
}

3) to set the status bar color of the whole application uniformly, the View controller-based status bar appearance in Info.plist is set to No (default is YES when not set ) ), using [UIApplication sharedapplication].statusbarstyle (preferred) adjustment. (Do not mix with other setup methods, not recommended)

In App Delegate: (can also be added to different positions according to different view)

[UIApplication sharedapplication].statusbarstyle = uistatusbarstylelightcontent;

or:

[UIApplication sharedapplication].statusbarstyle = Uistatusbarstyledefault;     

4) If you have navigationbar, you can set navigationbar style to adjust statusbar The color

Adjust Navigationbarstyle with Storyboard

or code:

[Viewcontroller.navigationbar Setbarstyle:uibarstyleblack];

2. Show and Hide

Show and hide StatusBar as long as it is overloaded in Uiviewcontroller:

-(BOOL) Prefersstatusbarhidden
{
return YES;
}

The same type of change requires the [self setneedsstatusbarappearanceupdate] method to be called

Add:

If both iOS6 and iOS7 are supported, the process is as follows:

1) If info.plist in View controller-based status bar appearance set to No.

Both iOS6 and iOS7 hide the status bar in the following way.

[[UIApplication sharedapplication] Setstatusbarhidden:yes Withanimation:no];

2) If view controller-based status bar appearance is set to Yes. (Default Yes if not set)

You need to determine whether the current is iOS6 or iOS7. If it is iOS6, it is also hidden through sharedapplication.

If it is iOS7, hide the status bar in a setneedsstatusbarappearanceupdate plus prefersstatusbarhidden way.

3. Animation effect

Now there are two kinds of animation effects: Uistatusbaranimationfade, uistatusbaranimationslide. From their name can be learned what his specific eye effect. Implementing animations requires overloading:

-(Uistatusbaranimation) preferredstatusbarupdateanimation
{
return uistatusbaranimationslide;
}

However, after overloading this method, there is no animation effect. At this point, we need to put [self setneedsstatusbarappearanceupdate] in the animation block execution:

[UIView animatewithduration:0.3
animations:^{
[Self setneedsstatusbarappearanceupdate];
}];

So the animation effect appears.  

4. Default No StatusBar

There are some applications that are not StatusBar by default:

Such an application is ugly, always feel the shortcomings of what, but some product managers are like.

To achieve this effect, you need to always set the status bar is initially hidden field to YES in the project configuration plist file, add the view controller-based status bar appearance field, and set the value To NO:

Additional reference: http://segmentfault.com/a/1190000003482218

Status Bar Summary

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.