【发布时间】:2017-07-19 09:25:46
【问题描述】:
我有 2 个 ViewController,第一个是 NavigationController 的 rootviewcontroller。我想在第二个视图控制器中删除导航栏的背景,并在顶部显示我的导航项。 怎么做 ?当我弹出第二个视图控制器时,我应该怎么做,导航栏有它的旧背景而不是 secendview 控制器背景?
这是我的代码:
@implementation testView1
- (void)viewDidLoad
{
[super viewDidLoad];
[button addTarget:self action:@selector(ClickAction) forControlEvents:UIControlEventTouchUpInside ];
self.navigationController.navigationBar.translatesAutoresizingMaskIntoConstraints = false;
self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.navigationItem.title = @"Home";
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
}
-(void)ClickAction
{
testView2 *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"V2"];
[self.navigationController pushViewController:detail animated:YES];
}
@implementation testView2
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor lightGrayColor];
self.title = @"No";
self.navigationController.navigationBar.barTintColor = nil;
self.navigationController.navigationBar.backgroundColor = nil;
self.navigationController.navigationBar.tintColor = nil;
self.navigationController.view.tintColor = nil;
self.navigationController.view.backgroundColor = nil;
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"left-arrow.png"] style:UIBarButtonItemStylePlain target:self action:@selector(Back:)];
backButtonItem.imageInsets = UIEdgeInsetsMake(45, 5, 45, 85);
self.navigationItem.leftBarButtonItem = backButtonItem;
}
-(void) Back:(id) sender
{
[self.navigationController popViewControllerAnimated:YES];
}
【问题讨论】:
标签: ios objective-c uinavigationcontroller uinavigationbar