美文网首页
Tab隐藏导航栏跳转到Nav控制器的导航颜色黑边问题

Tab隐藏导航栏跳转到Nav控制器的导航颜色黑边问题

作者: 金字塔的AI | 来源:发表于2019-02-13 15:31 被阅读7次

    假如从A跳转到B

    A是tab的一个界面,导航隐藏,在A中:

    - (void)viewWillAppear:(BOOL)animated{
        [super viewWillAppear:animated];
        self.tabBarController.tabBar.translucent = YES;
        [self.navigationController setNavigationBarHidden:YES animated:animated];
        self.fd_prefersNavigationBarHidden = YES;
      
    }
    - (void)viewWillDisappear:(BOOL)animated{
        [super viewWillDisappear:animated];
        self.tabBarController.tabBar.translucent = NO;
        [self.navigationController setNavigationBarHidden:NO animated:animated];
    }

    B是导航栏,在B中:

    -(void)viewWillAppear:(BOOL)animated

    {

        [self.navigationController setNavigationBarHidden:NO animated:animated];

        //设置导航条颜色

        self.navigationController.navigationBar.barStyle =UIStatusBarStyleLightContent;

        self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.46 green:0.77 blue:0.86 alpha:1.0];

        //设置返回按钮颜色

        self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

      //设置导航栏标题颜色

        NSDictionary *dict = @{NSForegroundColorAttributeName : [UIColor whiteColor]};

        [ self.navigationController.navigationBar setTitleTextAttributes:dict];

        [super viewWillAppear:YES];

    //自定义白色的返回按钮图片

        UIButton *leftbutton=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];

        [leftbutton setImage:[UIImage imageNamed:@"goBack"] forState:UIControlStateNormal];

        UIBarButtonItem *rightitem=[[UIBarButtonItem alloc]initWithCustomView:leftbutton];

        [leftbutton addTarget:self action:@selector(backToViewController) forControlEvents:UIControlEventTouchUpInside];

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

        negativeSpacer.width = -18;

        self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacer,rightitem, nil];

    }

    -(void)viewWillDisappear:(BOOL)animated{

        [super viewWillDisappear:animated];

        [self.navigationController setNavigationBarHidden:YES animated:animated];

    }

    完美解决所有问题

    相关文章

      网友评论

          本文标题:Tab隐藏导航栏跳转到Nav控制器的导航颜色黑边问题

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