0

Here is AppDelegate code, I'm running swift 5. Have you got any ideas on why my navigation bar title color is still black ?

var navigationBarAppearance = UINavigationBar.appearance()
var tabBarAppearance = UITabBar.appearance()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    FirebaseApp.configure()
    navigationBarAppearance.tintColor = UIColor.white
    tabBarAppearance.tintColor = UIColor.white
    navigationBarAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
    print(Realm.Configuration.defaultConfiguration.fileURL!)
    do{
        let _ = try Realm()
    }catch{
        print("Error initializing new realm, \(error)")
    }

    return true
}

1 Answers1

0

Add these lines in the method

var navigationBarAppearance = UINavigationBar.appearance()
var tabBarAppearance = UITabBar.appearance()

It should be something like this

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    FirebaseApp.configure()
    var navigationBarAppearance = UINavigationBar.appearance()
    var tabBarAppearance = UITabBar.appearance()
    navigationBarAppearance.tintColor = UIColor.white
    navigationBarAppearance.barTintColor = UIColor.white
    tabBarAppearance.tintColor = UIColor.white
    navigationBarAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
    print(Realm.Configuration.defaultConfiguration.fileURL!)
    do{
        let _ = try Realm()
    }catch{
        print("Error initializing new realm, \(error)")
    }

    return true
}

Finally, I understand your problem it is only for the latest ios. And you need there are some additionls if you are using ios 13.4.1
Then use this code:

 let coloredAppearance = UINavigationBarAppearance()
 coloredAppearance.configureWithOpaqueBackground()
 coloredAppearance.tintColor = UIColor.white
 coloredAppearance.barTintColor = UIColor.white
 ....         
UINavigationBar.appearance().standardAppearance = coloredAppearance
UINavigationBar.appearance().scrollEdgeAppearance = coloredAppearance

And it should be fine.

m1sh0
  • 2,236
  • 1
  • 16
  • 21