自定义navigationBar

 

1)改变返回按钮

//   需要在父视图设置backBarButtonItem
    UIBarButtonItem *backBtnItem = [[UIBarButtonItem alloc] init];
    backBtnItem.title = @"消息";
    self.navigationItem.backBarButtonItem = backBtnItem;
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];// 改变图片的颜色,由于是tintColor,因此在父视图和子视图设置均可
    

2). 改变按钮的颜色

    //改变全局navigationBar.barButtonItem的颜色
    [[UIBarButtonItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName: COLOR} forState:UIControlStateNormal];
     //如果需要个别定制,再添加下面这句
    [barButtonItem setTitleTextAttributes:@{NSForegroundColorAttributeName:CUSTOMCOLOR} forState:UIControlStateNormal];
  

3). 改变title的颜色

    //改变全局navigationBar中间title的颜色
    
    [controller.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: COLOR}];  
      //如果需要个别定制,在父视图中再添加下面这句
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:CUSTOMCOLOR}];

4).自定义UIBarButtonItem

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];  
    [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];  
    [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled];  
    [button setTitle:@"发送" forState:UIControlStateNormal];  
    [button addTarget:self action:@selector(compose) forControlEvents:UIControlEventTouchUpInside];  
    [button sizeToFit];  //没有这句butto是不会显示的 
      
    UIBarButtonItem * rightBarButton = [[UIBarButtonItem alloc] initWithCustomView:button];  
    rightBarButton.enabled = NO;  
    self.navigationItem.rightBarButtonItem = rightBarButton;  

5)设置隐藏

根据需求在 - (void)viewWillDisappear 或者 - (void)viewWillAppear 方法中写下面两句

self.navigationController.navigationBar.hidden=YES;

//无动画,相当于[self.navigationController setNavigationBarHidden:YES animated:NO];

[self.navigationController setNavigationBarHidden:YES animated:YES];//有动画,可避免push后,再通过左滑手势pop回来的一些视觉bug

例如:

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值