1.RootViewController:让一个控制器作为导航控制器的根控制器
2.导航栏的高度是44,状态栏的高度是20
3.在iOS7之前,self.view的坐标是从(0,64)开始的,在ios7之后,导航栏和状态栏全部透明,仍旧是(0,0)开始
4.navigationController是每一个视图控制器(UIViewController)都有的属性,如果说该控制器被放在某个导航控制器中管理,则能够直接拿到这个导航控制器,如果没有放到导航控制器中管理,则此属性对象为nil
5.push到下一个控制器:self.navigationControllerpushViewController:secondVCanimated:true];
6.Pop回到上一级界面:[self.navigationControllerpopViewControllerAnimated:true];
7. 拿到所有的子控制器的个数并设置标题
NSInteger count =
self.navigationController.viewControllers.count;
self.title = [NSStringstringWithFormat:@"第%ld个控制器",
count];
8.一般在iOS6中我们经常自定义返回上一级的按钮,但在iOS7以后,如果自定义返回上一级的按钮,则系统的抽屉式导航手势失效
9.设置导航栏的风格
self.navigationController.navigationBar.barStyle
=UIBarStyleBlack;
10.设置导航栏不透明
self.navigationController.navigationBar.translucent = false;
11.设置导航栏颜色
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
12.设置导航栏提示用户的内容(用得比较少)
self.navigationItem.prompt = @"hehehe";
13.设置导航栏title的字体的颜色,大小
self.navigationController.navigationBar.titleTextAttributes = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:20],
NSForegroundColorAttributeName: [UIColor redColor]};
14.自定义导航栏上的按钮
UIButton*btn = [UIButtonbuttonWithType:UIButtonTypeCustom];
[btnsetBackgroundImage:[UIImageimageNamed:@"btn_search.png"]forState:UIControlStateNormal];
btn.frame=
CGRectMake(0,0,33,32);
UIBarButtonItem*item4 = [[UIBarButtonItemalloc]initWithCustomView:btn];
self.navigationItem.rightBarButtonItem
= item4;
15.设置项目全局的导航栏的背景颜色
//注意:所有带UI_APPEARANCE_SELECTOR宏修饰的方法都可以全局设置
[[UINavigationBarappearance]
setBackgroundImage:img
forBarMetrics:UIBarMetricsDefault];
16.设置项目全局的导航栏的title字体颜色和大小
[[UINavigationBarappearance]setTitleTextAttributes:@{NSFontAttributeName:
[UIFont
boldSystemFontOfSize:16],NSForegroundColorAttributeName:
[UIColorwhiteColor]}];
17.设置状态栏:设置pilit文件中的View
controller-based status bar appearance
设为NO
//通过全局application去修改
[[UIApplicationsharedApplication]
setStatusBarStyle:UIStatusBarStyleLightContent];
18.隐藏/显示状态栏
[[UIApplicationsharedApplication]
setStatusBarHidden:self.navigationController.navigationBarHiddenwithAnimation:UIStatusBarAnimationFade];
19.隐藏导航栏
[self.navigationControllersetNavigationBarHidden:!self.navigationController.navigationBarHiddenanimated:true];
iOS导航控件与状态栏自定义详解
本文深入解析了iOS中RootViewController、导航栏、状态栏的使用方法及自定义技巧,包括如何设置导航栏高度、透明度、样式、按钮等元素,以及状态栏的隐藏与显示操作。

被折叠的 条评论
为什么被折叠?



