我的导航栏有三个组件:后退按钮,磁贴和其他自定义按钮。
我的目标是能够为该按钮添加自定义图像,但仍然遵循色调颜色逻辑。
在我设置的AppDelegate.m didFinishLaunchingWithOptions方法中:
ViewController *welcomeVC = [[ViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:welcomeVC];
navigationController.navigationBar.tintColor = [UIColor orangeColor];
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor orangeColor], NSForegroundColorAttributeName, nil]];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
然后在ViewController.m中我有:
- (void)viewWillAppear:(BOOL)animated
{
[self setUpImageBackButton];
}
- (void)setUpImageBackButton {
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(popCurrentViewController)];
}
-(IBAction)nextButtonTapped:(id)sender {
//create the second view
SecondViewController *secondController = [[SecondViewController alloc] initWithNibName:nil bundle:NULL];
secondController.title = @"SecondViewController";
[self.navigationController pushViewController:secondController animated:YES];
}
-(void)popCurrentViewController {
[self.navigationController popViewControllerAnimated:YES];
}
在上一个视图控制器中我有:
- (void)viewWillAppear:(BOOL)animated
{
[self setUpImageBackButton];
}
- (void)setUpImageBackButton {
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(popCurrentViewController)];
UIButton *settingsButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
[settingsButton setTitle:@"\u2699" forState:(UIControlStateNormal)];
[settingsButton.titleLabel setFont:[UIFont systemFontOfSize:30]];
[settingsButton addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:settingsButton];
self.navigationItem.rightBarButtonItem.tintColor = [UIColor orangeColor];
}
-(IBAction)nextButtonTapped:(id)sender {
//create the third view
ThirdViewController *thirdController = [[ThirdViewController alloc] initWithNibName:nil bundle:NULL];
thirdController.title = @"ThirdViewController";
[self.navigationController pushViewController:thirdController animated:YES];
}
-(void)popCurrentViewController {
[self.navigationController popViewControllerAnimated:YES];
}
我的问题是: