UI_NavigationController导航视图控制器
//navigationBar在竖屏状态下高度为64,横屏状态下为44
//设置背景图片
//[rootNC.navigationBar setBackgroundImage:[UIImage imageNamed:@"截图3.jpg"] forBarMetrics:UIBarMetricsDefault];
//设置辅助图片
//[rootNC.navigationBar setShadowImage:[UIImage imageNamed:@"截图2.jpg"]];
//背景色
//rootNC.navigationBar.barTintColor = [UIColor cyanColor];
//设置是否透明
// rootNC.navigationBar.translucent = YES;
//设置样式
//rootNC.navigationBar.barStyle = UIBarStyleBlack;
//rootNC.navigationBar.barStyle = UIBarStyleBlackOpaque;
//字体颜色
// rootNC.navigationBar.tintColor = [UIColor greenColor];
//设置标题颜色
//设置字体,设置颜色(前面的是设置字体,后面的是设置颜色)
//rootNC.navigationBar.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:30],NSForegroundColorAttributeName:[UIColor orangeColor]};
//导航栏中间标题
[self.navigationItem setTitle:@"首页"];
//标题视图
UIImageView*imgView = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"qq"]];
self.navigationItem.titleView=
imgView;
//左按钮
//self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"昨日" style:UIBarButtonItemStylePlain
target:self action:@selector(leftAction:)];
self.navigationItem.leftBarButtonItem=
[[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarkstarget:selfaction:@selector(leftAction)];
//UIBarButtonSystemItemCamera相机格式图标
//右按钮
UIImage*image = [UIImageimageNamed:@"shezhi"];
//图片作为barButtonItem时,系统会默认处理,提取出图片轮廓而不显示原有的内容.我们需要自己设置图片的绘制方式
image = [image
imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.navigationItem.rightBarButtonItem=
[[UIBarButtonItemalloc]initWithImage:imagestyle:UIBarButtonItemStylePlain target:selfaction:@selector(rightAction)];
任何一侧可以同时显示两个按钮
// //右边同时显示两个按钮
// UIBarButtonItem *right1 = [[UIBarButtonItem alloc]initWithTitle:@"后天"
style:UIBarButtonItemStylePlain target:self action:@selector(leftAction:)];
//修改颜色
//修改颜色
// right1.tintColor = [UIColor grayColor];
// UIBarButtonItem *right2 = [[UIBarButtonItem alloc]initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(leftAction:)];
// self.navigationItem.rightBarButtonItems = @[right1,right2];
//系统封装的出栈
//pop回去(对应push或者showViewContrlloer)
[self.navigationControllerpopViewControllerAnimated:YES];
//dismiss掉页面(对应present或者showDrtaiViewController)
// [self dismissViewControllerAnimated:YES completion:nil];
CustomViewController
*customVC = [CustomViewControllernew];
//系统封装的压栈
// [self.navigationController pushViewController:customVC animated:YES];
// //ios8之后,页面跳转的新方式(代替push和present)
// //模态跳转
// [self showDetailViewController:customVC sender:nil];
// //相当于push
[selfshowViewController:customVCsender:nil];
//自己写的压栈 //将第一个页面和第二个页面全部入栈(self先入栈,放在栈底,customVC后入栈,在self上面,所以此时显示的视图为customVC的视图)
// //ios8之后,页面跳转的新方式(代替push和present)
// //模态跳转
// [self showDetailViewController:customVC sender:nil];
// //相当于push
[selfshowViewController:customVCsender:nil];
//自己写的压栈 //将第一个页面和第二个页面全部入栈(self先入栈,放在栈底,customVC后入栈,在self上面,所以此时显示的视图为customVC的视图)
// [self.navigationController setViewControllers:@[self,customVC] animated:YES];
//自己写的出栈
// self.navigationController.viewControllers //是一个不可变数组,所以我们应该copy到一个可变数组中移除栈底的控制器
// //获取当前导航视图控制器所有的子控制器
// NSMutableArray *array = [self.navigationController.viewControllers mutableCopy];
// //移除自己(将栈顶的控制器移除)
// [array removeObject:self];
//// [array removeLastObject];
// //对导航视图控制器的子控制器重新赋值
//自己写的出栈
// self.navigationController.viewControllers //是一个不可变数组,所以我们应该copy到一个可变数组中移除栈底的控制器
// //获取当前导航视图控制器所有的子控制器
// NSMutableArray *array = [self.navigationController.viewControllers mutableCopy];
// //移除自己(将栈顶的控制器移除)
// [array removeObject:self];
//// [array removeLastObject];
// //对导航视图控制器的子控制器重新赋值
// self.navigationController.viewControllers = array;
传值
利用属性从前往后传值(需要在接收的页面声明为属性,发送的页面在push过去的创建接收页面的时候将值赋给那个属性) 注意:UI类(例如TextField)的必须声明一个字符串先存储这个text,再在接收的页面把string赋值给text
利用代理或者属性从后往前传值{在接收页面(第一个页面)push的位置创建第二个页面的时候将接收页面设置为发送页面(第二个页面)的代理[secondVC.delegate
= self],在接收页面写代理执行的方法(将发送页面的string赋给接收页面的text)[-(void)passValue:(NSString *)string{self.textField.text = string}],在发送页面的.h文件中创建协议(并声明将值传递过去的方法),声明delegate的属性,发送页面pop回去的位置让代理执行传递text的方法[_delegate
passValue:self.textField.text]}