ios UINavigationController

UINavigationController 导航控制器
配置导航栏 (NavigationBar)
** 高度:**算上状态栏 (Status Bar 本身高20个点) 高64个点
内容:通过navigationItem属性完成配置

中:title/titleView
左:leftBarButtonItem/s
右:rightBarButtonItem/s

** toolBar工具栏:**
高度44个点

UINavigationController 导航控制器:(写于代理方法里面)
通过navigationItem属性完成配置:

self.navigationController.navigationBarHidden = !self.navigationController.navigationBarHidden;//设置导航栏的隐藏属性
也可以使用set方法:
[self.navigationController setNavigationBarHidden:!self.navigationController.navigationBarHidden animated:YES];
[self.navigationController setToolbarHidden:!self.navigationController.toolbarHidden animated:YES]; //隐藏底部 toolBar
 self.navigationItem.title = @"新闻";
UIBarButtonItem *rightItem1 = [[UIBarButtonItem alloc]initWithTitle:@"按键" style:UIBarButtonItemStyleBordered target:self action:@selector(click:)];
    //创建一个的 barButtonItem 要求 是系统的 Add 样式
    UIBarButtonItem *rightItem2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil];
//    self.navigationItem.rightBarButtonItem =  rightItem1;
    self.navigationItem.rightBarButtonItems = @[rightItem1,rightItem1,rightItem1,rightItem2];
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

    
//创建一个导航控制器
UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:[[MyViewController alloc]init]];
//设置导航控制器 为 window 的rootViewController
self.window.rootViewController = navi;
[self.window makeKeyAndVisible];
return YES;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    MyViewController2 *myVc2 = [[MyViewController2 alloc]init];
    //navigationController 该属性可以获取到管理当前控制器的导航控制器实例
    [self.navigationController pushViewController:myVc2 animated:YES];
/      [self.navigationController popViewControllerAnimated:YES];
}

 //创建一个不受tintColor影响的图片(系统设置的渲染色影响很广)
    UIImage *leftImage = [[UIImage imageNamed:@"lxh_xiaohaha"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *leftItem1 = [[UIBarButtonItem alloc]initWithImage:leftImage  style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.leftBarButtonItem = leftItem1;

titleView:
 //中间 红色的view 高 40 宽 100 背景红色
    UIView *redView = [self crearView:CGRectMake(0, 0, 100, 40) andBackGroundColor:[UIColor redColor]];
    //子view 1  高 距离父view上下2 宽45 距离父view左边5 背景 绿色
    UIView *greenView = [self crearView:CGRectMake(5, 2, 45, 36) andBackGroundColor:[UIColor greenColor]];
    //子view 2  高 距离父view上下2 宽45 距离父view右边5 背景 蓝色
    UIView *blueView = [self crearView:CGRectMake(50, 2, 45, 36) andBackGroundColor:[UIColor blueColor]];
    [redView addSubview:greenView];
    [redView addSubview:blueView];
    self.navigationItem.titleView = redView;
-(UIView*)crearView:(CGRect)frame andBackGroundColor:(UIColor*)color {
    UIView *view  = [[UIView alloc]init];
    view.frame = frame;
    view.backgroundColor = color;
    return view;
}


//navigationItem 的设置 只在当前VC中生效
    //navigationBar 的设置 在当前导航控制器下的所有VC中都生效
    //设置导航栏的背景
//    self.navigationController.navigationBar.barTintColor = [UIColor redColor];

//设置 左 右 item 的颜色
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
//设置导航的样式
//    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    
    //换掉前面半透明的图片
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"image64"] forBarMetrics:UIBarMetricsDefault];


    //设置工具栏toolBar
    //把工具栏显示出来  默认是隐藏
    self.navigationController.toolbarHidden = NO;
    UIBarButtonItem *toolBarItem1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:nil action:nil];
    UIBarButtonItem *toolBarItem2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:nil action:nil];
    UIBarButtonItem *toolBarItem3 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:nil action:nil];
    //创建木棍特效
    UIBarButtonItem *fixItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    fixItem.width = 50;
    //弹簧特效
    UIBarButtonItem *flexibleItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    
    self.toolbarItems = @[toolBarItem1,fixItem,toolBarItem2,flexibleItem,toolBarItem3,fixItem];

导航下的传值:
委托方3件事,代理方3件事:
委托方:

//1. 制定协议:
@protocol RegisterViewControllerDelegate  <NSObject>
//代理方法的第一个参数是委托方本身
-(void)registerFinish:(RegisterViewController*)registerVC userInfo:(UserInfo*)info;
@end

//2. 设置代理人属性:
@property(nonatomic,weak)id<RegisterViewControllerDelegate> delegate;

代理方:
1. 遵守协议:
@interface LoginViewController () <RegisterViewControllerDelegate>
2. 实现代理方法:
-(void)registerFinish:(RegisterViewController *)registerVC userInfo:(UserInfo *)info {
    NSLog(@"%@ 委托我 执行代理方法",registerVC.name);
    self.userNameField.text = info.username;
    self.pwdField.text = info.password;
}
posted @ 2017-08-23 21:12  笑笑就好90  阅读(104)  评论(0编辑  收藏  举报