美文网首页iOS 知识点
iOS UINavigationController导航栏 设置

iOS UINavigationController导航栏 设置

作者: WS_0909 | 来源:发表于2017-04-27 09:51 被阅读39次
    1. 只有电池栏颜色变化 而且 没有导航栏那条横线
     UIView *statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, -20, kScreenWidth, 20)];
        
            statusBarView.backgroundColor = kBackgroundColor;
        
            [self.navigationController.navigationBar addSubview:statusBarView];
    
        
            [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
            //消除阴影
            self.navigationController.navigationBar.shadowImage = [UIImage new];
    
    1. 导航栏字体大小和颜色
     [self.navigationController.navigationBar setTitleTextAttributes:
         
         @{NSFontAttributeName:[UIFont systemFontOfSize:15],
           
           NSForegroundColorAttributeName:[UIColor whiteColor]}];
    

    设置状态栏和导航栏是一致的颜色

    self.navigationController.navigationBar.barTintColor = kBackgroundColor;
    
    self.navigationController.navigationBar.translucent = NO;
    

    设置透明的导航栏

     - (void)viewWillAppear:(BOOL)animated {
    
        [super viewWillAppear:animated];
    
        UIImage *image = [[UIImage alloc] init];
    
        //设置导航栏背景图片为一个空的image,这样就透明了
    
        [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    
        //去掉透明后导航栏下边的黑边
    
        [self.navigationController.navigationBar setShadowImage:image];
    
        self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    
        self.navigationController.navigationBar.translucent = YES;
    
    }
    
    
     - (void)viewWillDisappear:(BOOL)animated {
    
        [super viewWillDisappear:animated];
    
        [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    
        [self.navigationController.navigationBar setShadowImage:nil];
    
        self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    
        self.navigationController.navigationBar.translucent = NO;
    
    }
    

    相关文章

      网友评论

        本文标题:iOS UINavigationController导航栏 设置

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