UINavigation的相关操作:
①创建导航
FirstViewController *fvc = [[FirstViewController alloc] init];
//创建一个页面
UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:fvc];
//将这个页面作为导航控制器的根页面
self.window.rootViewController = nc;
②导航的各种
//导航条是属于导航的,针对导航条的设置,会影响整个导航
//self.navigationController.navigationBarHidden = YES;
//隐藏导航条
self.navigationController.navigationBar.barTintColor = [UIColor grayColor];
//导航条的背影色
// self.navigationController.navigationBar.translucent = YES;
//半透明状态,会影响坐标点{0,0}的位置
//如果是YES,0,0 在屏幕的左上角
//如果是NO,0,0在导航条的左下角
self.navigationController.navigationBar.tintColor = [UIColor redColor];
//导航条上展示内容的渲染色。(比如说系统自带的返回按钮的颜色)
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"aaa"] forBarMetrics:UIBarMetricsDefault];
//设置背景图,如果图片的大小正好是320*44(640*88),那么就会显示成iOS7以前的风格(状态条和导航条分开了)
//导航条的高度是64(44+20)
③设置导航上的文字和按钮。。。。
1 /* 2 * 专用按钮(barButtonItem)的4种创建方法 3 * 1,用文字 4 * 2,用系统样式 5 * 3,用图片 6 * 4,用自定义视图 7 */ 8 9 10 //self.navigationItem的设置是针对当前页面的 11 12 self.navigationItem.hidesBackButton = YES; 13 //隐藏当前页面的返回按钮 14 15 self.navigationItem.title = @"桔色"; 16 //设置title,下一页的返回按钮上的文字会显示当前页的title 17 18 UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 30)]; 19 titleLabel.backgroundColor = [UIColor yellowColor]; 20 titleLabel.text = @"aaa"; 21 titleLabel.textAlignment = NSTextAlignmentCenter; 22 titleLabel.font = [UIFont systemFontOfSize:18]; 23 self.navigationItem.titleView = titleLabel; 24 //设置一个view显示在当前页面的导航条的中间 25 [titleLabel release]; 26 27 UIBarButtonItem *abbi = [[UIBarButtonItem alloc] initWithTitle:@"ab" style:UIBarButtonItemStyleBordered target:self action:@selector(bbiClick)]; 28 //使用文字创建一个专用按钮 29 self.navigationItem.leftBarButtonItem = abbi; 30 [abbi release]; 31 32 UIBarButtonItem *bbbi = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(bbiClick)]; 33 //使用系统风格创建专用按钮 34 // self.navigationItem.rightBarButtonItem = bbbi; 35 // [bbbi release]; 36 37 UIBarButtonItem *cbbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"gerenzhuye"] style:UIBarButtonItemStyleBordered target:self action:@selector(bbiClick)]; 38 //使用图片创建专用按钮,图片大小一般用30*30(60*60) 39 //只取图片的形状,不取颜色。颜色会使用导航条的渲染色 40 // self.navigationItem.rightBarButtonItem = cbbi; 41 // [cbbi release]; 42 43 UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 30)]; 44 btn.backgroundColor = [UIColor grayColor]; 45 [btn setTitle:@"btn" forState:UIControlStateNormal]; 46 [btn addTarget:self action:@selector(bbiClick) forControlEvents:UIControlEventTouchUpInside]; 47 48 UIBarButtonItem *dbbi = [[UIBarButtonItem alloc] initWithCustomView:btn]; 49 //使用自定义的view创建一个专用按钮 50 [btn release]; 51 52 // self.navigationItem.rightBarButtonItem = dbbi; 53 // [dbbi release]; 54 55 self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:bbbi, cbbi, dbbi, nil]; 56 //设置一组专用按钮
④回到之前的页面
[self.navigationController popViewControllerAnimated:YES];//回到上一页
[self.navigationController popToRootViewControllerAnimated:YES];//回到根页面
[self.navigationController popToViewController:某个页面 Animated:YES];
ToolBar
①self.navigationController.toolbarHidden = NO;//让底部的UIToolbar(工具条)显示出来,针对整个导航控制器的,高度是44
②self.navigationController.toolbar.barTintColor = [UIColor brownColor];//背景色
③self.navigationController.toolbar.tintColor = [UIColor redColor];//渲染色
④self.navigationController.toolbar setBackgroundImage:[UIImage imageNamed:@""] forToolbarPoisition:UIBarPositonBottom barMetrics:UIBarMetricsDefault];//背景图片
⑤UIBarButtonItem *ddi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];//特殊的专用按钮,存在的意义就是为了占位,使两个按钮之间不至于紧挨着
⑥self.toolbarItems = [NSArray arrayWithObjects:,,,];
圆角的设置
btn.layer.masksToBounds = YES;
btn.layer.cornerRadius = 50;//圆角的弧度
btn.layer.borderColor = [[UIColor magentaColor] CGColor];//边框颜色
btn.layer.borderWidth = 2;//边框的大小