在導航欄使用背景圖檔:
如果您的應用程式使用了自定義圖像作為欄的背景,你需要提供一個“更大”的圖檔,使其延伸了狀态欄的後面。導航欄的高度現在是從44點(88像素)更改為64點(128像素)。
仍然可以使用了setBackgroundImage:方法來指定自定義圖像的導航欄。下面是代碼行設定背景圖檔:
[[UINavigationBarappearance]setBackgroundImage:[UIImageimageNamed:@"nav_bg.png"]forBarMetrics:UIBarMetricsDefault];
效果圖和上面的一樣,我就不貼出來了。
改變導航欄标題的字型
就像iOS
6,我們可以通過使用導航欄的“titleTextAttributes”屬性來自定義的文本樣式。可以指定字型,文字顔色,文字陰影顔色,文字陰影在文本标題偏移屬性字典,使用下面的文本屬性鍵:
UITextAttributeFont - 字型
UITextAttributeTextColor- 文字顔色
UITextAttributeTextShadowColor - 文字陰影顔色
UITextAttributeTextShadowOffset - 偏移用于文本陰影
NSShadow*shadow = [[NSShadowalloc]init];
shadow.shadowColor= [UIColorcolorWithRed:0.0green:0.0blue:0.0alpha:0.8];
shadow.shadowOffset= CGSizeMake(0,1);
[[UINavigationBarappearance]setTitleTextAttributes: [NSDictionarydictionaryWithObjectsAndKeys:
[UIColorcolorWithRed:245.0/255.0green:245.0/255.0blue:245.0/255.0alpha:1.0], NSForegroundColorAttributeName,
shadow, NSShadowAttributeName,
[UIFontfontWithName:@"HelveticaNeue-CondensedBlack"size:21.0], NSFontAttributeName,nilnil]];
使用圖檔作為導航欄标題
不想标題欄是光秃秃的文字?可以通過使用代碼行中的圖像或标志取代它:簡單地改變titleview用來自定義,(适用于較低版本)
self.navigationItem.titleView= [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"appcoda-logo.png"]];
效果如下,我随便用了個圖檔,别介意:

添加多個欄按鈕項目
您希望添加導航欄的一側不止一個欄按鈕項目,無論是leftBarButtonItems和rightBarButtonItems
您在導航欄左側/右側指定自定義欄按鈕項目。比如你想添加一個攝像頭和一個共享按鈕右側的吧。您可以使用下面的代碼:
UIBarButtonItem*shareItem = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemActiontarget:selfaction:nilnil];
UIBarButtonItem*cameraItem = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCameratarget:selfaction:nilnil];
NSArray*itemsArr = @[shareItem,cameraItem];
self.navigationItem.rightBarButtonItems= itemsArr;

自定義後退按鈕的文字和顔色
通常情況下,我們使用UINavigationController時,push到的子頁面,左上角會是系統自動取值上一層父頁面的title名稱,預設情況是這樣,那麼我們該如何修改它呢?

左側顯示了父頁面的title:使用者登入,可是我們想修改成傳回,方式有很多,舉些例子
方法一:
通過設定navigationItem的backBarButtonItem可以直接更換文字,【注意,要在父視圖的Controller中設定】如下:
UIBarButtonItem*item = [[UIBarButtonItemalloc]initWithTitle:@"傳回"style:UIBarButtonItemStylePlaintarget:nilaction:nil];
self.navigationItem.backBarButtonItem= item;
效果如下:

所有的子界面傳回時都變成了我們定義的文字,如果不想顯示文字,直接"",就會單獨顯示一個系統的傳回箭頭圖示,也是很清晰的感覺。
做到這裡發現文字顔色和背景有重複,那麼如何自定義其顔色呢?在iOS7,可以改變tintColor屬性,它提供了一個快速和簡單的方式,下面是一個示例代碼片段:
[[UINavigationBarappearance]setTintColor:[UIColorwhiteColor]];
效果如下:

全是系統的圖示和文字,這回看着舒服了,有木有?【除了後退按鈕,請注意,tintColor屬性影響所有按鈕标題和按鈕圖像】
最後舉個例子,另外一種實作自定義導航控制器傳回按鈕,代碼如下:
[self.navigationController.navigationBarsetTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColorredColor],NSFontAttributeName:[UIFontsystemFontOfSize:19.0]}];
self.title=[NSStringstringWithFormat:@"第%lu頁",(unsignedlong)self.navigationController.viewControllers.count];
//自定義傳回按鈕
UIImage*backButtonImage = [[UIImageimageNamed:@"fanhui.png"]resizableImageWithCapInsets:UIEdgeInsetsMake(0,30,0,0)];
[[UIBarButtonItemappearance]setBackButtonBackgroundImage:backButtonImageforState:UIControlStateNormalbarMetrics:UIBarMetricsDefault];
//将傳回按鈕的文字position設定不在螢幕上顯示
[[UIBarButtonItemappearance]setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin)forBarMetrics:UIBarMetricsDefault];
效果如下:

最後說一下使用pushViewController切換到下一個視圖時,navigation
controller按照以下3條順序更改導航欄的左側按鈕(本段摘自網絡):
1、如果B視圖有一個自定義的左側按鈕(leftBarButtonItem),則會顯示這個自定義按鈕;
2、如果B沒有自定義按鈕,但是A視圖的backBarButtonItem屬性有自定義項,則顯示這個自定義項;
3、如果前2條都沒有,則預設顯示一個後退按鈕,後退按鈕的标題是A視圖的标題;
本文摘自:
http://blog.csdn.net/mad1989/article/details/41516743