1
votes

In a child view controller, we are changing the navigation bar tint color on viewWillAppear, and then, to ensure the parent view controller's navigation bar tint color is restored, we set it's color on willMove in the child view controller.

  override func viewWillAppear(_ animated: Bool) {
    self.navigationController?.navigationBar.barTintColor = .black
  }

  override func willMove(toParentViewController parent: UIViewController?) {
    self.navigationController?.navigationBar.barTintColor = UIColor(red: 30, green: 30, blue: 30)
  }

The colors does not change correctly. This is the interaction:

  • Visit parent controller, color is correct gray
  • Visit child controller, (triggering viewWillAppear) color is the correct black
  • Go back to parent controller, (triggering willMove) color is a darker gray than intended

When you go back to the parent controller from the child controller, the color is lighter than the RGB value of what it is actually being set to.

The same RGB value is being set in the storyboard and displays on initial load of the parent view before the child view is visited.

enter image description here

1
check this post stackoverflow.com/questions/39835420/… and i also recommend you to move your willMove code to viewWillDisappear and try?Joe
If all your code is in a view controller, I'd put things in either viewWillAppear() or viewWillLayoutSubviews(), depending on your needs. Seems more of a proactive way to do things.dfd

1 Answers

0
votes

If you are using Xcode 8 and iOS 10 the default color space should be sRGB when choosing your colors in the color picker.

See here for more information: Apple doc