Practical tips for iOS development-uinavigationbar and status bar

Source: Internet
Author: User

IOS7 after the Uinavigationbar and status bar has undergone a series of changes, if you do not need to be compatible with iOS7 after the device, according to some information on the internet to solve the problem will step on some pits. In iOS 7, we can modify the appearance of the status bar in each view controller, and the status bar before IOS7 is in white style. Setting the background color before iOS7 also requires a background view overlay, and iOS7 only needs to set the Bartintcolor color.

Uinavigationbar Settings

1. Set the background color:

[Self.navigationController.navigationBar Setbartintcolor:[uicolor Redcolor];

The effect is as follows:

2.Translucent is set to transparency, and setting it to Yes has a blur effect:

[Self.navigationController.navigationBar Settranslucent:yes];

Effect set to No:

3. Set the background picture, the picture style needs to apply according to the situation, the calling method is SetBackgroundImage:

    [Self.navigationController.navigationBar setbackgroundimage:[uiimage imagenamed:@ "Flyelephant.png"] forbarmetrics : Uibarmetricsdefault];

4. Set Navigationbar title size and color, before setting is through Uitextattributefont,uitextattributetextcolor, The Uitextattributetextshadowcolor and Uitextattributetextshadowoffset settings now need to be set according to the attributes that begin with the NS:

    Nsdictionary  *[email Protected]{nsforegroundcolorattributename:[uicolor whitecolor],nsfontattributename:[ Uifont systemfontofsize:20]};        [Self.navigationController.navigationBar settitletextattributes:textattributes];

5.NavigationBar set the middle title or Custom view:

    [Self.navigationitem settitle:@ "Travel"];    [Self.navigationitem settitleview:[uiimage imagenamed:@ "Flyelephant"];

6. Single or multiple left and right item settings:

Single Leftitem settings:

   Uibarbuttonitem  *leftbarbutton=[[uibarbuttonitem alloc]initwithimage:[uiimage imageNamed:@ "BackIcon"] style: Uibarbuttonitemstyleplain target:self Action: @selector (Popback)];    [Leftbarbutton settintcolor:[uicolor colorwithwhite:0 alpha:1];    Self.navigationitem.leftbarbuttonitem=leftbarbutton;

The effect is as follows:

Multiple Rightitem settings:

    Uibarbuttonitem *firstitem=[[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemreply target: Self Action:nil];    Uibarbuttonitem *seconditem=[[uibarbuttonitem Alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemtrash target : Self Action:nil];    Nsarray *[email Protected][firstitem, SecondItem];    Self.navigationitem.rightbarbuttonitems=rightitems;

The effect is as follows:

status bar (StatusBar) settings

iOS7 before the status bar is always white style, we do not have much room to modify, after IOS 7, we can modify the appearance of the status bar in each controller, for example, during the day and night mode switching process we can modify the status bar color. The time on the status bar, the battery indicator, and the Wi-Fi signal are dimmed by default, as shown, but we can modify the Uibarstyle and then preferredstatusbarstyle the Overwrite method:

[Self.navigationController.navigationBar Setbarstyle:uibarstyleblack];

The final implementation is to overwrite the Preferredstatusbarstyle method in the controller: (if the above code does not write is not executed to the Preferredstatusbarstyle method)

-(Uistatusbarstyle) preferredstatusbarstyle{    return uistatusbarstylelightcontent;}

The effect is as follows:

Hiding the status bar only needs to overwrite Prefersstatusbarhidden:

-(BOOL) prefersstatusbarhidden{    return YES;

The effect is as follows:

If you need to refresh the status bar again, you can control it through setneedsstatusbarappearanceupdate ~

Practical tips for iOS development-uinavigationbar and 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.