标签:
------创建UINavigationController----
导航控制器,继承UIViewController
作用:管理多个ViewController之间的逻辑层次和切换
通过第一个视图控制器viewController, 作为导航控制器的第一个根视图控制器
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: settingVC];
将nav作为window的根视图控制器
self.window.rootViewController = nav;
//切换(切换的动画无效)
[self.navigationController pushViewController:abtVC animated:YES];//abtVC入栈 //正向切换,需要先实例化
//反向(不需要实例化,可通过self.navigationController.viewControllers得到所有的视图,然后根据需要选择需要退回的视图,确定其下标即可)
[self.navigationController popViewControllerAnimated:YES];//将当前控制器出栈
[self.navigationControllerpopToViewController:self.navigationController.viewControllers[1] animated:YES];//返回前面两个界面
[self.navigationController popToRootViewControllerAnimated:YES];//退回到根视图
//navigationBar的设置——属于navigationController,公共的
//navigationBar: 属于navigationController的,覆盖在viewController 上面
//隐藏
self.navigationController.navigationBar.hidden = YES;
//背景颜色
//纯色 (barTintColor)
self.navigationController.navigationBar.barTintColor =[UIColor redColor];
//设置背景图片
self.navigationController.navigationBar setBackgroundImage: forBarMetrics:(UIBarMetricsDefault纵屏 UIBarMetricsCompact 横屏)
//navigationItem的设置 ——属于viewController的
leftBarButtonItem
rightBarButtonItem
btn.frame = CGRectMake(0, 0, 40, 40);
[btn setTitle:@"注册" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *leftBar = [[UIBarButtonItem alloc] initWithCustomView:btn];
self.navigationItem.leftBarButtonItem = leftBar;
title/titleView
//添加标题,显示在navigationBar
self.title = @"主页";
//self.navigationItem.title = @"主页";
//修改title的颜色(通过Bar设置颜色,特殊情况)
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor redColor] forKey:NSForegroundColorAttributeName];
backBarButtonItem
//------------修改backBarButtonItem-----------
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
标签:
原文地址:http://my.oschina.net/u/2448151/blog/512136