UINavigationController 导航控制器 是iOS中提供的多视图控制器,用来管理多个视图控制器,自身携带一个视图,视图上方带有导航条 UINavigationBar
创建导航控制器
在AppDelegate.m中
建立一个根视图控制器,指定为导航控制器的根视图控制器,并将导航控制器指定为window的根视图控制器
配置属性
在单视图控制器内配置导航控制器的属性
self.view.backgroundColor = [UIColor yellowColor];
//配置导航条公共属性
[self configureCommonProperty];// self.navigationController.navigationBar 取得公共导航条
//配置当前界面的导航条属性
[self customizeNavigationBar];//self.navigationItem 取得当前导航条
//该属性作用于所有受导航控制器管理的界面
- (void)configureCommonProperty {
//1.设置导航条的颜色
self.navigationController.navigationBar.barTintColor =[UIColor cyanColor];
//2.是否要毛玻璃效果
self.navigationController.navigationBar.translucent =NO ;//默认yes 会影响视图分布 当设置颜色或图片后,失效
//3.设置导航条上内容的渲染颜色
self.navigationController.navigationBar.tintColor = [UIColor redColor];
//4.是否隐藏导航条
self.navigationController.navigationBarHidden = NO;//默认为no
//5.配置背景图片
/*不同图片尺寸,导航条上显示的效果也不同
小于44像素 将图片拉伸,显示在导航条以及状态条上
等于44像素 图片只会显示在导航条上
大于44像素 小于64像素 将图片平铺在导航条以及状态条上
大于64像素 将图片显示在导航条和状态条上
*/
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"NavBar_64"] forBarMetrics:UIBarMetricsDefault];
//6.设置导航条标题文字和颜色
NSDictionary *dic = @{NSFontAttributeName: [UIFont systemFontOfSize:20], NSForegroundColorAttributeName: [UIColor greenColor]};
self.navigationController.navigationBar.titleTextAttributes = dic;
}
//定制当前界面导航条的内容
- (void )customizeNavigationBar {
//1.配置导航条的显示的文字
self.navigationItem.title = @"主页";
//2.配置标题视图
UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"消息",@"电话"]];
self.navigationItem.titleView =segment;
[segment release];
//配置左边内容 显示更新按钮
UIBarButtonItem *btnItem = [[UIBarButtonItem alloc] initWithTitle:@"刷新" style:UIBarButtonItemStylePlain target:self action:@selector(handleLeft:)];
self.navigationItem.leftBarButtonItem = btnItem;
[btnItem release];
// 配置右边内容,显示添加按钮
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(handlrRight:)];
跳转模式
self.navigationController 得到管理该视图管理器的导航控制器
push 进入
pop 返回
模态 present