Xcode 11.3.1, iOS 13
I'm trying to change the color of the navigationBar on all View Controllers if a certain condition exists in the app. Seemed logical to use the same code that sets the global color initially, using a delegate function in AppDelegate.
Here's my code:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var myColor : UIColor?
let themeColorUS = UIColor(red: 0.991, green: 0.621, blue: 0.022, alpha: 1.00)
let themeColorCanada = UIColor(red: 0.001, green: 0.686, blue: 0.000, alpha: 1.00)
let themeColorGeneral = UIColor(red: 0.000, green: 0.954, blue: 0.969, alpha: 1.00)
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UserDefaults.standard.setValue(false, forKey: "_UIConstraintBasedLayoutLogUnsatisfiable")
setBarColors(issuingFlag: "General")
return true
}
...
func setBarColors(issuingFlag:String) {
if issuingFlag == "US" {
myColor = themeColorUS
}else if issuingFlag == "Canada"{
myColor = themeColorCanada
}else{
myColor = .magenta
}
print("issuingFlag == \(issuingFlag)")
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = myColor
appearance.titleTextAttributes = [.foregroundColor: UIColor.black]
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.black]
UINavigationBar.appearance().tintColor = .black
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().compactAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
} else {
UINavigationBar.appearance().tintColor = .black
UINavigationBar.appearance().barTintColor = myColor
UINavigationBar.appearance().isTranslucent = false
}
}
In addition to the initial call to setBarColors() when the app opens (which works fine) I also call it from a viewController within the app like so, which does nothing to the navBars, even though the function is receiving the appropriate data in its parameter:
if detailFlag.issuedBy == "Canada"{
appDelegate.setBarColors(issuingFlag: "Canada")
}else if detailFlag.issuedBy == "US"{
appDelegate.setBarColors(issuingFlag: "US")
}
Can someone help me out as to why the function's not switching the navBar colors?
TIA!

