Solution
I have been doing Angela's course and have faced the same problem. He is my solution.
Setup navigation bar
Firstly, I configured my navigation bar; I checked the standard and scroll edges under appearances.
ChatViewController
I created a setup function to set my navigation bar and apply the desired background colour.
func setupNavbar(){
title = K.appName
navigationItem.hidesBackButton = true
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
navigationController?.navigationBar.standardAppearance = appearance
navigationController?.navigationBar.scrollEdgeAppearance?.backgroundColor = UIColor(named: K.BrandColors.purple)
}
You can then call this function from your viewDidLoad. Like this:
override func viewDidLoad() {
super.viewDidLoad()
setupNavbar()
tableView.dataSource = self
tableView.delegate = self
tableView.register(UINib(nibName: K.cellNibName, bundle: nil), forCellReuseIdentifier: K.cellIdentifier)
loadMessage()
}
Welcome Screen
The above code will change the setup for your navigation bar for the entire application. To fix this, I implemented the viewWillApear of the WelcomeViewController so that the nav bar would be fixed every time the welcome screen was added to the view hierarchy.
override func viewWillAppear(_ animated: Bool) {
let appearance = UINavigationBarAppearance()
appearance.configureWithTransparentBackground()
navigationController?.navigationBar.standardAppearance = appearance
navigationController?.navigationBar.scrollEdgeAppearance = appearance
}
Since the other two screens can only be reached by navigating to the welcome screen first, you don't need to change any other code.
Demo
Here is a screenshot of what my UI looks like.