假如从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];
}
完美解决所有问题
网友评论