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