UI - NavigationController

/************************************* 导航栏的定制 *************************************/
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

    //设置导航控制器:
    //1.创建一个根视图控制器
    ViewController *vc = [[ViewController alloc]init];
    //2.vc作为导航控制器的根视图控制器
    UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:vc];
    //3.导航控制器是window的根视图控制器
    self.window.rootViewController = navi;
    navi.view.backgroundColor = [UIColor whiteColor];

/************************************* 导航控制器推出视图 *************************************/
    SecondViewController *svc = [[SecondViewController alloc]init];

//    采用出栈入栈的方式推出下个页面 push pop 先进(栈底)后出(栈顶)
    //1.进入下一个视图控制器
    [self.navigationController pushViewController:svc animated:YES];
    //2.返回上一个视图控制器
    [self.navigationController popToRootViewControllerAnimated:YES];
    //3.返回指定的视图控制器
    [self.navigationController popToViewController:svc animated:YES];
    //4.返回到根视图控制器
    [self.navigationController popToRootViewControllerAnimated:YES];

    //常用属性
    //1.所有处于栈中的控制器
    self.navigationController.viewControllers;
    //2.位于栈顶的控制器
    self.navigationController.topViewController;
    //3.当前正在显示的控制器
    self.navigationController.visibleViewController;
    //4.导航条
    self.navigationController.navigationBar;

/************************************* 导航控制器的创建 *************************************/

//    一、对导航栏的定制: 影响每个子视图
//    self.navigationController.navigationBar
    //(1)半透明效果(默认打开, 若关闭, 左边原点会在导航栏的左下方, 整个屏幕下移)
    self.navigationController.navigationBar.translucent = YES;
    //调整: 状态栏20 导航栏44(横屏 32)

    //(2)背景颜色(最上层导航栏)
    self.navigationController.navigationBar.barTintColor = [UIColor yellowColor];
    //(最下层导航栏)
    self.navigationController.navigationBar.backgroundColor = [UIColor blackColor];

    //(3)添加导航栏的背景图片, 半透明效果自动关闭
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"2.jpg"] forBarMetrics:UIBarMetricsDefault];

//    二、设置当前控制器显示在导航栏上的信息
//    self.navigationController.navigationItem
    //(1)设置标题
    //1.第一种方式:推荐
    self.navigationItem.title = @"第一页";
    //2.第二种方式: 会影响其他的东西
//    self.title = @"首页";
    //(2)自定义标题视图
    self.navigationItem.titleView = [[UISegmentedControl alloc]initWithItems:@[@"消息", @"电话"]];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(leftBarButtonAction:)];

//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"变色" style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonAction:)];

    //使用矢量图: 百度阿里巴巴矢量图
//    imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal(取消渲染)
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"4.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonAction:)];
    //渲染颜色设置
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值