5
- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"这是个bug?->";
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:68/255.0 green:155/255.0 blue:235/255.0 alpha:1.0];
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};

    UIBarButtonItem *rightItem0 = [[UIBarButtonItem alloc] initWithTitle:@"我会变灰" style:UIBarButtonItemStylePlain target:self action:@selector(recordButtonClick)];
    [rightItem0 setTintColor:[UIColor whiteColor]];

    self.navigationItem.rightBarButtonItems = @[rightItem0];
}

- (void)recordButtonClick{
    [self.navigationController pushViewController:[NextViewController new] animated:YES];
}

The top right UIBarButtonItem always highlighted:

image

Why is the UIBarButtonItem "我会变灰" on the top right always highlighted? Is it a bug in iOS 11.2?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
ame017
  • 53
  • 3

1 Answers1

14

Is it a bug in iOS 11.2?

Yes. There's an iOS 11 bug with the right bar button item in the root view controller. When you push to the next view controller and pop back, the right bar button item is dimmed.

That is the bug seen in your screencast. In your code, you set the right bar button item's tint color to white. And initially, it is white. But when you push and then pop, it is no longer white.

What I do is work around this in the view controller's viewWillAppear, as follows:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.navigationBar.tintAdjustmentMode = .normal
    self.navigationController?.navigationBar.tintAdjustmentMode = .automatic
}
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Still not fixed under 11.2.1 :( I set a small workaround.. if(button.isEnabled == true) {button.isEnabled = false; button.isEnabled = true} and this does fix it. – Pascale Beaulac Dec 15 '17 at 20:38
  • @MaudeBeaulac added code showing my current workaround – matt Dec 15 '17 at 20:44