1. 给当前导航栏加一个标题
self.navigationItem.title = @"猫眼电影";
2. 设置背景颜色(不是所有的背景颜色都是 backGroundColor)
self.navigationController.navigationBar.barTintColor = [UIColor greenColor];
3. 设置导航栏左边图标 并 绑定方法
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(leftButtonAction:)] autorelease];
4. 为了防止坐标系被篡改,我们把bar从半透明设置成不透明,这样坐标系的原点会自动向下推64
self.navigationBar.translucent = NO;
5. 指定一些视图, 称为titleView
UISegmentedControl *segment = [[UISegmentedControlalloc] initWithItems:@[@"信息", @"通话"]];
self.navigationItem.titleView = segment;
6. navigation导航栏的背景颜色
self.navigationController.navigationBar.barTintColor = [UIColor redColor]
7. segue 跳转之前的准备
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// 获取目的控制器
UITableViewController *tableVC = segue.destinationViewController;
// 给联系人导航条设置标题(传值)
tableVC.navigationItem.title = [NSString stringWithFormat:@"%@的私人通讯录", self.countTextField.text];
}
8. 获取所有导航条外观
UINavigationBar *bar = [UINavigationBar appearance];
NSString *backgroundIcon = [NSString stringWithFormat:@"NavBar64"];
UIImage *backgroundImage = [UIImage imageNamed:backgroundIcon];
设置所有导航条 的背景图片
[bar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
设置所有导航条 的 title 属性
NSDictionary *dictionary = @{
NSForegroundColorAttributeName: [UIColor whiteColor],
NSFontAttributeName: [UIFont systemFontOfSize:17],
};
[bar setTitleTextAttributes:dictionary];
9. 重写父类的跳转下一页方法
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
// 只要继承这个类 push 下一页时 会隐藏tabBar
viewController.hidesBottomBarWhenPushed = YES;
[super pushViewController:viewController animated:animated];
}