导航控制器UINavigationController

来源:互联网 发布:kdj优化背离源码 编辑:程序博客网 时间:2024/06/15 17:16

这里写图片描述

1.导航控制器属于栈结构 本身不显示内容 需要一个主视图控制器来显示内容

  UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:fvc];

2.UINavigationController以栈的形式保存子控制器

@property(nonatomic,copy) NSArray *viewControllers;@property(nonatomic,readonly) NSArray *childViewControllers;//只读

3.使用push方法能将某个控制器压入栈

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;

4.使用pop方法可以移除控制器

//将栈顶的控制器移除- (UIViewController *)popViewControllerAnimated:(BOOL)animated;//回到指定的子控制器- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;//回到根控制器(栈底控制器)- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated;

5.定制navigationBar

 //设置导航条的样式    nc.navigationBar.barStyle = UIBarStyleDefault;    //设置是否透明    nc.navigationBar.translucent = YES;    //一定设置不透明 那么在控制器的view添加控件时默认的0,0坐标是在导航条的左下方    //设置颜色 镂空颜色    nc.navigationBar.tintColor = [UIColor greenColor];    //导航栏整体的颜色    nc.navigationBar.barTintColor = [UIColor yellowColor];    //设置导航图片    [nc.navigationBar setBackgroundImage:[UIImage imageNamed:@"header_bg.png"] forBarMetrics:UIBarMetricsDefault];//    iOS7以后,如果添加的导航条图片的像素高度正好是44或者88,则会自然的添加到状态条的下面,如果该图片的像素高度不等于44或88,导航条会被添加到状态条下层,即导航条的起始位置紧贴屏幕的上端    //隐藏导航条//    [nc setNavigationBarHidden:YES animated:YES];

6.UINavigationItem这个在控制器中设置属性

//返回按钮@property(nonatomic,retain) UIBarButtonItem *backBarButtonItem;//中间的标题视图@property(nonatomic,retain) UIView          *titleView;//中间的标题文字@property(nonatomic,copy)   NSString        *title;//左上角的视图@property(nonatomic,retain) UIBarButtonItem *leftBarButtonItem;// 右上角的视图@property(nonatomic,retain) UIBarButtonItem *rightBarButtonItem;//左上角试图数组@property(nullable,nonatomic,copy) NSArray<UIBarButtonItem *> *leftBarButtonItems //右上角试图数组@property(nullable,nonatomic,copy) NSArray<UIBarButtonItem *> *rightBarButtonItems 
0 0
原创粉丝点击