1

My problem is exactly as explained in this question ViewController title color will change change color when back button clicked

I've Navigation Controller -> View Controller (#1) -> Segue to another View Controller (#2)

View Controller #2 has a different title color.

When I click on Back button in View Controller #2 to go back to Home View (#1) it's title color is not changed to what it should be but it remain the title colour of view controller #2.

I've set the correct title color in attribute inspector. I'm also setting title color exclusively in Home View Controller's viewWillAppear but it's colour is still not changed.

I'm wondering what else I need to do? Is there

I've already added code to set title color to white in Home View Controller's viewWillAppear

override func viewWillAppear(_ animated: Bool){
    super.viewWillAppear(animated)
    print("HomeViewController: viewWillAppear()")

    // Mark: - Set navigation bar title color
    setTitleColorWhite(vc: self)

    activityIndicator.startAnimating()
    fetchDetails()
}

And this is setTitleColorWhite

// Mark: - Set navigation bar title color
func setTitleColorWhite(vc: UIViewController){
    let attrs = [
        NSAttributedStringKey.foregroundColor: UIColor(red:1.00, green:1.00, blue:1.00, alpha:1.0),
        NSAttributedStringKey.font: UIFont(name: "SFProText-Medium", size: 17.0)!
    ]
    vc.navigationController?.navigationBar.titleTextAttributes = attrs
}
Matt
  • 315
  • 2
  • 6
  • 20
  • It may not call the attribute again if VC#1 remains in memory try setting it in ViewWillAppear like in this https://stackoverflow.com/a/26076698/2081663 answer – Ben Avery Jul 31 '18 at 23:51
  • It's already there. I've updated my question showing the code. It doesn't work despite that. – Matt Aug 01 '18 at 00:11

1 Answers1

1

Update the color in HomeViewController's viewDidAppear instead of viewWillAppear

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    setTitleColorWhite(vc: self)
}
Kamran
  • 14,987
  • 4
  • 33
  • 51