This article just collected some of the information I saw about the custom navigation bar.
There are two ways to customize the navigation bar style:
1. Use [Uinavigationbar apperance] To add a style to all the Navigationbar on the entire application, which is a global style setting.
2. Of course if you want to add a specific style to a particular navigationbar, you can find the current bar instance by Self.navigationController.navigatinoBar and then style it.
The second method, presumably we all know, the relevant information search a lot, not cumbersome.
The first method, if given to the entire application, you can customize a customnavigationcontroller inherit from Uinavigationcontroller, and then rewrite the Init method in Customnavcontroller
+ (void) Initialize {
//1.appearance method returns the appearance object of a navigation bar
// Modify the Appearance object, which is equivalent to modifying the appearance of the whole project
uinavigationbar *navigationbar = [uinavigationbarappearance];
[Navigationbarsetbartintcolor:kcolornavbar];
[Navigationbar settintcolor: [uicolorwhitecolor]]; IOS7 , set the color of the Navigationbaritem text
//3. Set the theme of the navigation bar text
Nsshadow *shadow = [[nsshadowalloc]init];
[Shadowsetshadowoffset:Cgsizezero];
[Navigationbar settitletextattributes:@{nsforegroundcolorattributename : [uicolorwhitecolor],
nsshadowattributename : Shadow}];
[Navigationbar setbackgroundimage:[uiimage imagenamed:@ "ic_cell_bg_selected"] Forbarmetrics:uibarmetricsdefault ];
//4. Modify All the appearance of Uibarbuttonitem
uibarbuttonitem *barbuttonitem = [uibarbuttonitemappearance];
if (kisios7ormore) {
[Barbuttonitemsettintcolor: [uicolorwhitecolor]];
}Else {
// Modify The item's background image
//[baritem setbackgroundimage:[uiimage imagenamed:@ "Navigationbar_button_background.png"] ForState:UICon Trolstatenormal Barmetrics:uibarmetricsdefault];
//[baritem setbackgroundimage:[uiimage imagenamed:@ "Navigationbar_button_background_pushed.png"] ForStat E:uicontrolstatehighlighted Barmetrics:uibarmetricsdefault];
// Modify The text style above the item
nsdictionary *dict =@{nsforegroundcolorattributename : [uicolorWH Itecolor],
nsshadowattributename : Shadow};
[Barbuttonitem settitletextattributes:d ICTforstate:uicontrolstatenormal];
[Barbuttonitem settitletextattributes:d ICTforstate:uicontrolstatehighlighted];
}
// Modify the return button style
[Barbuttonitem setbackbuttonbackgroundimage:[uiimage imagenamed:@ "Ic_back"] Forstate:uicontrolstatenormal Barmetrics:uibarmetricscompact];
//5. Set the status bar style
[[uiapplicationsharedapplication]setstatusbarstyle: Uistatusbarstylelightcontent];
}
If you want to customize the return button style, you can override the following methods
// Override Back button
-(void) Pushviewcontroller: (uiviewcontroller *) Viewcontroller animated: (BOOL) animated
{
[Superpushviewcontroller: Viewcontrolleranimated: animated];
< Span style= "COLOR: #000000" > if (Viewcontroller. Navigationitem Leftbarbuttonitem = = nil && self Viewcontrollers Count 1 ) {
Viewcontroller. Navigationitem. Leftbarbuttonitem = [selfcreatbackbutton];
}
}
-(uibarbuttonitem *) Creatbackbutton
{
< Span style= "COLOR: #000000" > return [[ uibarbuttonitem alloc " initwithimage:[ uiimage imagenamed: @ "Ic_back" ] style: Uibarbuttonitemstyleplain target: self action: @ Selector (popself)];
or [[Uibarbuttonitem alloc]initwithtitle:@] return "Style:uibarbuttonitemstyleplain target:self Action: @selector (popself)];
}
-(void) popself
{
[self popviewcontrolleranimated:YES];
}
In addition, say a few details of the navigation bar:
after iOS7, the default style of the status bar and navigation bar is linked together, but in fact the position and size of the navigation bar is the same as the previous system version, is still affixed to the status bar below, is still high 44px; the user seems to be connected together, This is because the _uinavigationbarbackground in the Uinavigationbar is positioned in the Y direction -20px position, and then the height is increased to 64px, which can simultaneously serve as the background of both. So you need to provide a height of 64px navigation bar background map.
The things about customizing the navigation bar Uinavigationcontroller