iOS导航栏相关属性以及常见需求

    //修改导航栏字体颜色及字体大小
    [self.navigationController.navigationBar setTitleTextAttributes:@{
                                                                      NSForegroundColorAttributeName : [UIColor blueColor], NSFontAttributeName : [UIFont systemFontOfSize:18] }];
    
    
    //设置导航栏背景颜色
    [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
    //设置导航栏无透明背景颜色
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"colorpic"] forBarMetrics:UIBarMetricsDefault];  //照片为对应颜色的随意大小的背景图,这样不会有透明度
    //设置导航栏没有边界线
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    
    //当设置导航栏没有任何颜色时:
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    
    //设置导航栏透明
    self.navigationController.navigationBar.translucent = YES;
    
    //要隐藏导航栏时
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
    //当我们隐藏导航栏时,往往会出现状态栏statusBar未能被试图覆盖,导致试图最上方有一长条。所以要设置当前控制器:
    self.automaticallyAdjustsScrollViewInsets = NO;//来取消导航栏对顶端的影响。
    
    //设置导航栏样式,UIBarStyleDefault是默认样式,UIBarStyleBlack是黑色不透明。UIBarStyleBlackOpaque和UIBarStyleBlackTranslucent这两个已经废弃了
    [self.navigationController.navigationBar setBarStyle:UIBarStyleBlack];
    //开启导航栏左滑后退
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    //若果想在某个界面禁止左滑
    - (void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
        if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
            self.navigationController.interactivePopGestureRecognizer.enabled = NO;
        }
    }
    
    - (void)viewWillDisappear:(BOOL)animated {
        if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
            self.navigationController.interactivePopGestureRecognizer.enabled = YES;
        }
    }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值