I have an app with a tab view on the bottom. The tab view has its color set when a main view controller is displayed. Browse into other views by using the navigation control and back. It displays the tab bar in the right color as normal.
The problem is that when the screen is locked or the user switches to another app and then back to my app (unlock screen or switch back to my app), the tab view loses its color and looks transparent. This makes other inactive tabs hard to see.
The main table view looks OK and keeps its color. Just the tab bar becomes transparent.
I have a class called GradientViewController as a base class for defining colors for the table view and navigation bar.
class GradientViewController: UIViewController
{
func gradientView_UpdateBackgroundColors() {
let tv = getTableView()
// This call works fine to set table view color
gvHelper.updateBackgroundColorsFor(
backgroundView1: tv,
backgroundView2: view)
gvHelper.updateNavigationBarColors(
navigationController)
}
...
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
gradientView_UpdateBackgroundColors()
}
}
Here is my helper class to update the navigation bar:
class GradientViewHelper {
...
func updateNavigationBarColors(
_ nv: UINavigationController?) {
guard let nv = nv else { return }
let bar = nv.navigationBar
// top and bottom colors are UIColor type and initialized at init
bar.barTintColor = colorTop
bar.backgroundColor = colorTop
if let bar = nv.toolbar {
bar.barTintColor = colorBottom
bar.backgroundColor = colorBottom
}
}
Not sure what is missing? One way to fix this issue is to catch the event when my app is back in focus from the lock screen or back from other apps, and set up the bottom color. I'm not sure what event I could catch. The attached images are snapshots of the problem.