您的位置:首页 > 产品设计 > UI/UE

UI初级第五课  导航控制器——iOS学习连载20

2015-08-19 08:31 453 查看
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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: