美文网首页
导航栏的隐藏和显示

导航栏的隐藏和显示

作者: Leon1024 | 来源:发表于2018-11-18 23:23 被阅读0次

隐藏和显示导航栏

//  最好统一使用带动画的方法,animated的值和转场动画保持一致
- (void)viewWillAppear:(BOOL)animated{
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

//  三个方法的区别
    // 隐藏导控件的导航栏组件,可以使用滑动手势popViewController, 不带导航栏显示或隐藏的过度动画
    self.navigationController.navigationBar.hidden = YES;
    
    // 隐藏整个导航控件, 不能使用滑动手势popViewController, 不带导航栏显示或隐藏的过度动画
    [self.navigationController setNavigationBarHidden:YES];
    
    // 隐藏整个导航控件, 不能使用滑动手势popViewController, 带导航栏显示或隐藏的过度动画
    [self.navigationController setNavigationBarHidden:YES animated:YES];

导航栏的基本设置

/* 设置导航栏不透明,默认是透明
     注意:尽量不要去设置 translucent 半透明度,如果需要设置透明或者不透明,应设置SetBackgroudImage
         如果为NO,则self.view的原点Y是从导航栏下边开始的
     */
    self.navigationController.navigationBar.translucent = NO;
    
    // 透明的导航栏,使用透明图片的方法
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    
    // 去掉导航栏底部阴影线,使用透明图片的方法
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    
    // 导航栏背景色底色,半透明的
    self.navigationController.navigationBar.backgroundColor = UIColor.greenColor;
    
    // 导航栏颜色,不透明
    self.navigationController.navigationBar.barTintColor = UIColor.greenColor;
 
    // 标题颜色
    self.title = @"导航栏测试";
    NSDictionary *dic = @{NSForegroundColorAttributeName : UIColor.magentaColor};
    [self.navigationController.navigationBar setTitleTextAttributes:dic];
    
    // 默认导航按钮的颜色
    self.navigationController.navigationBar.tintColor = UIColor.magentaColor;

相关文章

网友评论

      本文标题:导航栏的隐藏和显示

      本文链接:https://www.haomeiwen.com/subject/esmnfqtx.html