标签:
一个iOS的app很少只由一个控制器组成,除非这个app极其简单
当app中有多个控制器的时候,我们就需要对这些控制器进行管理
有多个view时,可以用一个大的view去管理1个或者多个小view
控制器也是如此,用1个控制器去管理其他多个控制器
为了便于管理控制器,iOS提供了2个比较特殊的控制器("父控制器")
UINavigationController
UITabBarController
注意:NavigationController的NavigationBar的 的高度 是44,不包括状态栏的状态
@property(nonatomic,readonly) NSArray *childViewControllers
@property(nonatomic,copy) NSArray *viewControllers;
注意:
childViewControllers :是在UIViewController中属性,并且只读
viewControllers:是在UINavigationController中的属性
因此添加子控制器可以利用
navc.viewControllers = @[vc1,vc2];、
当导航控制器使用push的动画形式添加两个控制器的时候,然后利用childViewControllers获取子控制器对象,打印时候,会显示只有一个
解决办法:动画设置为NO 即可
导航控制器是一种栈的结构(先进后出),
第一个入栈的控制器为rootViewController
方法:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (UIViewController *)popViewControllerAnimated:(BOOL)animated;
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated;
// 设置标题
self.navigationItem.title
self.title
// 设置左右按钮
self.navigationItem.leftBarButtonItem
self.navigationItem.leftBarButtonItems
self.navigationItem.rightBarButtonItem
self.navigationItem.rightBarButtonItems
// 设置标题为自定义view
self.navigationItem.titleView
// nav bar 颜色
[self.navigationController.navigationBar setBackgroundColor:[UIColor redColor]]; // 仅仅是导航条的颜色
[self.navigationController.navigationBar setTintColor:[UIColor redColor]]; // 主题(按钮)颜色
[self.navigationController.navigationBar setBarTintColor:[UIColor redColor]]; // 导航条+状态栏颜色
// 设置bar不透明
self.navigationController.navigationBar.translucent = NO;
// 设置自定义标题属性
// title
NSDictionary* attr = @{ NSFontAttributeName : [UIFont systemFontOfSize:10],NSForegroundColorAttributeName : [UIColor redColor] };
[self.navigationController.navigationBar setTitleTextAttributes:attr];
// titleView
UILabel* titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
titleLabel.font = [UIFont boldSystemFontOfSize:20];
titleLabel.textColor =[UIColor orangeColor];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.text = @"自定义标题";
self.navigationItem.titleView = titleLabel;
// 导航条设置自定义图片为按钮(原始图 不渲染)
UIImage* image = [UIImage imageNamed:@"navigationbar_friendsearch_highlighted"];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
IOS开发UI篇-NavigationController的基本使用
标签:
原文地址:http://www.cnblogs.com/gaox97329498/p/4711749.html