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];