Modify the color of the status bar font in IOS7

Source: Internet
Author: User


the font for the status bar is black: Uistatusbarstyledefault

the font for the status bar is white: Uistatusbarstylelightcontent


first, in info.plist , set the View controller-based status bar appearance to NO


The color of the status bar font is set only by the following property, which is white by default:

Default is Uistatusbarstyledefault

[UIApplication Sharedapplication].statusbarstyle


How to solve the different color of status bar font in individual VC


1. In Info.plist, set the view controller-based status bar appearance to No.

2, in the app delegate:

[UIApplication sharedapplication].statusbarstyle = uistatusbarstylelightcontent;


3, in the individual status bar font color is not the same VC


-(void) Viewwillappear: (BOOL) animated{

[UIApplication sharedapplication].statusbarstyle = Uistatusbarstyledefault;

}


-(void) Viewwilldisappear: (BOOL) animated

{

[Super viewwilldisappear:animated];

[UIApplication sharedapplication].statusbarstyle = uistatusbarstylelightcontent;

}


second, in info.plist , the View controller-based status bar appearance is set to YES, or not set.


The default value for View controller-based status bar appearance is yes.


If view controller-based status bar appearance is yes.

The [uiapplication Sharedapplication].statusbarstyle is invalid.


Use the following method:

1, in the VC rewrite VC Preferredstatusbarstyle method.

-(Uistatusbarstyle) Preferredstatusbarstyle

{

return uistatusbarstyledefault;

}

2. Call in Viewdidload: [Self setneedsstatusbarappearanceupdate];


However, when the VC in Nav, the above method is useless , VC Preferredstatusbarstyle method does not have to be called.

The reason is that [self setneedsstatusbarappearanceupdate] is issued,

Only the Preferredstatusbarstyle method in the navigation controller is called.

The Preferredstatusbarstyley method in VC will not be called.


There are two solutions:

Method One:

Setting the Barstyle property of NavBar affects the font and background color of the status bar. As follows.

The font for status bar is white

The background color of the navigation bar is black.

Self.navigationController.navigationBar.barStyle = Uibarstyleblack;

The font for status bar is black

The background color of the navigation bar is white, and the background color of the status bar is white.

Self.navigationController.navigationBar.barStyle = Uibarstyledefault;


Method Two:

Customize the subclass of a nav bar, overriding the Preferredstatusbarstyle method in this subclass:

mynav* nav = [[Mynav alloc] INITWITHROOTVIEWCONTROLLER:VC];

Self.window.rootViewController = nav;


@implementation Mynav


-(Uistatusbarstyle) Preferredstatusbarstyle

{

uiviewcontroller* TOPVC = Self.topviewcontroller;

return [TOPVC Preferredstatusbarstyle];

}



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.