学习笔记-导航栏控制器

导航控制器(UINavigationController)

导航控制器:其功能是导航,而非显示视图

  • 导航控制器的创建
    • 通过一个根视图控制器创建导航控制器
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:rootVC];

rootVC根视图控制器

1.导航功能:
  • push进一个控制器
[self.navigationController pushViewController:[[RootViewController alloc]init ] animated:YES];


  • pop到上一个控制器
[self.navigationController popViewControllerAnimated:YES];

  • popto 到指定控制器
[self.navigationController popToViewController:vc animated:YES];

  • pop 到根视图控制器
[self.navigationController popToRootViewControllerAnimated:YES];

2.导航栏UI:
  • 导航栏标题
  • 导航栏标题
self.navigationItem.title = @"系统提供导航栏标题";
  • 自定义导航栏标题视图
    UIView *titleview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
    titleview.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.titleView = titleview;
    
    
  • 导航栏按钮(左/右)
  • 系统和提供:
    UIBarButtonItem *rightItem1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:nil action:nil];
    
    
  • 自定义:
    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
    [button setImage:[UIImage imageNamed:@"write"] forState:UIControlStateNormal];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    self.navigationItem.rightBarButtonItems = rightItem;
    
  • 导航栏属性
//0.是都隐藏导航栏
    self.navigationController.navigationBarHidden = NO;

    //1.半透明效果 默认yes
    self.navigationController.navigationBar.translucent = NO;

    //2.导航栏样式
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

    //3.设置导航栏的item颜色
    self.navigationController.navigationBar.tintColor = [UIColor redColor];

    //4.导航栏的颜色
    self.navigationController.navigationBar.barTintColor = [UIColor lightGrayColor];

    //5.设置导航栏的背景图片
    /**
     *  UIBarMetricsCompact      : 横屏
        UIBarMetricsDefault      : 竖屏
     */
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar_bg_normal"] forBarMetrics:UIBarMetricsDefault];


你可能感兴趣的:(学习笔记-导航栏控制器)