UINavigationBar

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] init];
    self.window.frame = [UIScreen mainScreen].bounds;
    [self.window makeKeyAndVisible];
    //有一个视图控制器才能有导航控制器
    ViewController *vc = [[ViewController alloc] init];
    //将navigation嵌套进viewcontroller
    UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:vc];

    self.window.rootViewController = navigation;
    //设置导航栏Bar的颜色
    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:34/255.0 green:199/255.0 blue:1.0 alpha:1.0]];

    //设置导航栏title字体的颜色,大小
    [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,[UIFont systemFontOfSize:25],NSFontAttributeName, nil]];
    //设置导航栏返回按钮的颜色
    [[UINavigationBar appearance] setTintColor:[UIColor yellowColor]];

    //设置运营商、电池、时间字体颜色设置为白色
    [[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];

    return YES;
}

//ViewController
//懒加载
- (UIButton *)pushButton{
    if (_pushBtn == nil) {
        _pushBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        _pushBtn.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width-60)/2, 100, 60, 30);
        _pushBtn.backgroundColor = [UIColor redColor];
        [_pushBtn setTitle:@"懒加载" forState:UIControlStateNormal];
    }
    return self.pushBtn;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    /**
     *  导航控制器
        UINavigationController  导航控制器的层次结构

        继承于UIViewController
        导航控制器的作用?
        它采用栈的原理来管理视图控制器
        (toolbar默认隐藏)
     */

//    UINavigationController
    self.view.backgroundColor = [UIColor greenColor];
    self.navigationController.toolbarHidden = NO;
    self.view.window.backgroundColor = [UIColor blueColor];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(0, 0, 100, 45);
    button.backgroundColor = [UIColor colorWithRed:40/255.0 green:176/255.0 blue:249/255.0 alpha:1];
    button.layer.borderColor = [[UIColor redColor] CGColor];
    button.layer.borderWidth = 2;
    button.layer.cornerRadius = 6;
    [button setTitle:@"下一页" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont boldSystemFontOfSize:20];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.center = self.view.center;
    [self.view addSubview:button];
    [button addTarget:self action:@selector(pushButtonAction) forControlEvents:UIControlEventTouchDown];
//    self.title = @"Root";不推荐使用
    //导航栏中间的title
    self.navigationItem.title = @"Root";
    UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [titleButton setTitle:@"touch me" forState:UIControlStateNormal];
    [titleButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [titleButton addTarget:self action:@selector(titleButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//    self.navigationItem.titleView = titleButton;
    _titleView = [[UIView alloc] initWithFrame:CGRectMake(10, 24, 100, 100)];
    _titleView.backgroundColor = [UIColor blueColor];
    _titleView.hidden = YES;
//    [self.view addSubview:_titleView];

    //加载到window上
    //拿到window
    UIWindow *window = [[UIApplication sharedApplication].windows lastObject];//拿到自己创建window
    window.backgroundColor = [UIColor redColor];
    [window addSubview:_titleView];
    //导航栏左边存在BarButtonItem
    UIBarButtonItem *leftBarButtonItem1 = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:nil];
    UIBarButtonItem *leftBarButtonItem2 = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:nil];


    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:nil];

//    self.navigationItem.leftBarButtonItems = @[];放多个Item

    /**设置Item的间距
     *      UIBarButtonSystemItemFlexibleSpace,系统默认的,不可用设置距离
     *      UIBarButtonSystemItemFixedSpace,可以设置距离
     *
     *
     */

    UIBarButtonItem *spaceBarbuttonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];

    spaceBarbuttonItem.width = 10;

    self.navigationItem.leftBarButtonItems = @[leftBarButtonItem1,spaceBarbuttonItem,leftBarButtonItem2];

    [self pushButton];
    [self.view addSubview:_pushBtn];


}

- (void)titleButtonAction:(UIButton *)sender {
    NSLog(@"点我");
    _titleView.hidden = !_titleView.hidden;
}

- (void)pushButtonAction {

    NSLog(@"点击到A页面");
    AViewController *Avc = [[AViewController alloc] init];
//    [self presentViewController:Avc animated:YES completion:^{
//    }];模态推送
    //当视图控制器被压入导航控制器中,就具备了navigationController
    [self.navigationController pushViewController:Avc animated:YES];//导航控制器推送
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值