自定义导航栏:
1.改变的是所有导航栏的背景颜色
[[UINavigationBar appearance]setBarTintColor:[UIColor yellowColor]];
2.首先要改变导航条背景颜色(里面返回按钮,或者字体的颜色(back))设置的是全局的,所有的页面都是
[[UINavigationBar appearance]setTintColor:[UIColor yellowColor]];
以上两种的设置要在appdelegate中设置
3.隐藏导航栏,在根基视图的基础上设置的,根以后的都会被隐藏
[self.navigationController setNavigationBarHidden:YES];
4.这种方式设置的标题,只能从根基开始取到,子视图结束。其余的视图不变,而且,根基视图的标题默认居中
self.title = @"hello";
5.将narBarView放入导航栏,这个view会被自动居中
self.navigationItem.titleView = navBarView;(这个navBarView是我门创建的view)
6.导航栏上的按钮
在导航栏上建立按钮,类似于button按钮
UIBarButtonItem *buttonRight = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(button:)];
在导航栏右边设置按钮
self.navigationItem.rightBarButtonItem = buttonRight;
在导航栏左边添加按钮
UIBarButtonItem *buttonLeft = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(button:)];
self.navigationItem.leftBarButtonItem = buttonLeft;
7.导航栏上的按钮UIBarButtonItem
* UIBarButtonSystemItemDone 按钮样式为文字Done、
* UIBarButtonSystemItemAdd 按钮样式为图片的加号
*UIBarButtonSystemItemCamera 按钮样式是图片的照相机
*UIBarButtonSystemItemFixedSpace 是一个占位符 ,可以设置width
*UIBarButtonSystemItemFlexibleSpace 是一个占位符,固定宽度,导航栏上单独一个按钮,样式不能用这个
设置导航栏右侧多个按钮
self.navigationItem.rightBarButtonItems = @[button2, button1];
8.view的坐标都是从导航栏左下点开始计算
self.edgesForExtendedLayout = UIRectEdgeNone;
使用文字作为导航栏的按钮
UIBarButtonItem *buttong = [[UIBarButtonItem alloc]initWithTitle:@"return" style:UIBarButtonItemStylePlain target:self action:@selector(button:)];
self.navigationItem.leftBarButtonItem = buttong;
9.使用图片作为导航栏返回按钮
UIBarButtonItem *bar = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"bb_1a@2x.png"] style:UIBarButtonItemStylePlain target:self action:@selector(button:)];
self.navigationItem.leftBarButtonItem = bar;
10.显示toolbar
[self.navigationController setToolbarHidden:NO];