Introduction to Uinavigationbar (navigation bar view) in iphone

Source: Internet
Author: User

in multi-view applications, we often use custom Uinavigationbar to complete the navigation bar settings.

1. Create a navigation bar

Uinavigationbar *navigationbar = [[Uinavigationbar alloc] Initwithframe:cgrectmake (0, 0, 320, 44)];


2. With the navigation bar, you must set up an item collection on the navigation bar to place the middle caption, and the left and right buttons, because the space above is limited, only the left and right two buttons.

Create a navigation bar collection

Uinavigationitem *navigationitem = [[Uinavigationitem alloc] initwithtitle:nil];

3. Set the navigation bar style (using the system's own style)

[NavBar Setbarstyle:uibarstyledefault];




typedef ns_enum (Nsinteger, uibarstyle) {uibarstyledefault = 0, Uibarstyleblack = 1, uibarsty Leblackopaque = 1,//Deprecated. Use Uibarstyleblack uibarstyleblacktranslucent = 2,//Deprecated. Use Uibarstyleblack and set the translucent property to YES};



literally we can understand the approximate meaning of these 4 styles:
the following were:
Uibarstyledefault: Default Style
Uibarstyleblack: Black
uibarstyleblackopaque: Black opaque
uibarstyleblacktranslucent: Black Transparent


Note: We found that in the back two marks for deprecated, we know that using the latter two kinds will not be advocated.
from the enumeration we can also see that uibarstyleblack=1 and uibarstyleblackopaque=1 are the same.
later, it was found that a method was added: [NavBar settranslucent:yes]; used to indicate transparency.

So, we use Uibarstyledefault and uibarstyleblack to define the Uinavigationbar style, and use the Settranslucent: method to set the transparency or not.

3. Customize the navigation bar color

if only using these 4 (2 styles * is transparent), it is hard to avoid, you must be able to customize the Uinavigationbar style ah.

[NavBar setbackgroundimage:[uiimage imagenamed: @ "picture name"] Forbarmetrics:uibarmetricsdefault];

the second parameter of the SetBackgroundImage method requires an explanation:

Uibarmetricsdefault: Displays the standard size of the Uinavigationbar when vertical (take the phone) Uinavigationbar
Uibarmetricslandscapephone: Displays the standard size of the uinavigationbar when it is sideways Uinavigationbar

This article is from the "Wodenianshao Technology blog" blog, make sure to keep this source http://wodenianshao.blog.51cto.com/10604330/1694060

Introduction to Uinavigationbar (navigation bar view) in iphone

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.