1、設置導航欄中間的標題:
self.title=@"popover";
2、設置導航欄的 標題 文字顏色:
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
3、設置NavigationBar背景顏色
[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:20/255.0 green:155/255.0 blue:213/255.0 alpha:1.0]];
4、設置UIBarButtonSystemItem 的圖標 的顏色:
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(clickPopoverButton:)];
barButtonItem.tintColor=[UIColor whiteColor]; //改變UIBarButtonSystemItem的顯示顏色
self.navigationItem.rightBarButtonItem = barButtonItem;
5、設置導航欄標題的 字體顏色、文字陰影、文字大小:
NSShadow *navTitleShadow = [[NSShadow alloc]init];
navTitleShadow.shadowColor=[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
navTitleShadow.shadowOffset = CGSizeMake(0, 5);
[self.navigationController.navigationBar setTitleTextAttributes:
@{NSForegroundColorAttributeName:[UIColor greenColor],/*[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0]*/
NSShadowAttributeName:navTitleShadow,
NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0]
}];
6、使用圖片作為導航欄標題。設置了 titleView 后,標題自動會隱藏:
self.title=@"popover";
self.navigationItem.titleView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"qrcode_screen"]];
7、添加多個欄按鈕項目:
UIBarButtonItem *shareItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(clickPopoverButton:)];
UIBarButtonItem *cameraItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(clickPopoverButton:)];
self.navigationItem.rightBarButtonItems = @[shareItem,cameraItem]; //從右往左
8、自定義后退按鈕的文字和顏色(這代碼寫在push前的控制器里才有效):
UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backItem;
9、改變 “返回”圖標和文字 的顏色
只有執行了下面代碼,“返回”圖標和文字才會變色,所以是放在執行push前,所有 UIBarButtonSystemItem 的都會變設置的顏色:
self.navigationController.navigationBar.tintColor=[UIColor whiteColor];
10、有導航欄時,獲取是在第幾頁:
self.title = [NSString stringWithFormat:@"第%lu頁",(unsigned long)self.navigationController.viewControllers.count];
11、將返回按鈕的文字position設置不在屏幕上顯示
[[UIBarButtonItem appearance]setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];
12、設置左邊按鈕和back按鈕同時存在:
//在push進去的控制器里設置
self.navigationItem.leftItemsSupplementBackButton = YES;
//13、設置 titleView 的背景顏色:
self.navigationItem.titleView.backgroundColor=[UIColor redColor];