iOS implements custom status bar StatusBar and navigation bar Navigationbar status and color

Source: Internet
Author: User

Many apps can see the color of the status bar with the navigation bar, and it's really raozui.

I. Change the status bar color (StatusBar)

For example, the navigation bar is red and the status bar is green.

To achieve this effect is very simple, is to add a background view.

The simple implementation process is as follows:

1     //set navigation colors available2 [Self.navigationController.navigationBar setbartintcolor:[uicolor redcolor];3     //Create a false status bar with a height of 204UIView *statusbarview = [[UIView alloc] Initwithframe:cgrectmake (0, - -, Self.view.bounds.size.width, -)];5     //set into green6Statusbarview.backgroundcolor=[Uicolor Greencolor];7     //Add to Navigationbar8[Self.navigationController.navigationBar Addsubview:statusbarview];

Two. Customizing the colors of StatusBar and Navigationbar

Say again. Font and color for the title of the navigation bar

The effect is as follows:

The code is as follows:

1     // Attributes Property 2     Nsdictionary  *[email Protected]{nsforegroundcolorattributename:[uicolor whitecolor],nsfontattributename:[ Uifont systemfontofsize:+]}; 3     // Set the font size  color of the navigation bar 4     [Self.navigationController.navigationBar settitletextattributes:textattributes];

Three. Hide Navigationbar and StatusBar

The effect is as follows:

The code is as follows:

1 //     Hide Navigationbar (nav bar)2//    [Self.navigationcontroller Setnavigationbarhidden:yes]; 3       [Self.navigationcontroller Setnavigationbarhidden:yes Animated:yes];

The effect is as follows:

The code is as follows:

1 // Hide status bar  rewrite Prefersstatusbarhidden2 - (BOOL) Prefersstatusbarhidden3{  4     return//  Yes hidden 5 }

Four. Status bar font Color white

The code is as follows:

Method One:

1     // Set status bar font white 2     // default Black Uibarstyledefault 3     // White Uibarstyleblack; Uibarstyleblackopaque;  Uibarstyleblacktranslucent4    [Self.navigationController.navigationBar setbarstyle: Uibarstyleblack]; 5     // [[UIApplication sharedapplication] setstatusbarstyle:uistatusbarstylelightcontent];

Method Two:

1 // status bar Font white override Preferredstatusbarstyle method 2 - (uistatusbarstyle) preferredstatusbarstyle3{4     // Uistatusbarstylelightcontent White 5     // uistatusbarstyledefault      Black 6     return uistatusbarstylelightcontent; 7 }

Five. Set the background picture of the navigation bar

The effect is as follows:

The code is as follows:

1 // set the background picture of the navigation bar 2     // set the transparency effect of Navigationbar 3     [Self.navigationController.navigationBar setbackgroundimage:[uiimage imagenamed:@ " navigation bar background picture "] Forbarmetrics:uibarmetricsdefault];

The above contents refer to:

Application of Uinavigationbar and status bar instances in iOS development and hiding various bar//http://www.111cn.net/sj/ios8/90056.htm

IOS implements a custom navigation bar background as well as a custom color status bar (supports 7.0 and lower versions)//http://www.cnblogs.com/wt616/p/3784717.html

iOS implements custom status bar StatusBar and navigation bar Navigationbar status and color

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.