UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white]

Powyższy kod umieściłem w pliku AppDelegate, tytuł nadal ma kolor czarny.

0
Priyanka Kadam 2 kwiecień 2020, 14:59

3 odpowiedzi

Najlepsza odpowiedź

Możesz spróbować z tym:

if #available(iOS 13.0, *) {
    let appearance                      = UINavigationBarAppearance()
    appearance.backgroundColor          = .purple
    appearance.titleTextAttributes      = [.foregroundColor: UIColor.white]
    appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]

    UINavigationBar.appearance().tintColor            = .white
    UINavigationBar.appearance().standardAppearance   = appearance
    UINavigationBar.appearance().compactAppearance    = appearance
    UINavigationBar.appearance().scrollEdgeAppearance = appearance
} else {
    UINavigationBar.appearance().tintColor     = .white
    UINavigationBar.appearance().barTintColor  = .purple
    UINavigationBar.appearance().isTranslucent = false
}
1
Frankenstein 2 kwiecień 2020, 12:15

Spróbuj tego,

let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.red]
        UINavigationBar.appearance().titleTextAttributes = textAttributes
0
Vandana pansuria 2 kwiecień 2020, 13:02

Powyższy problem wystąpił, gdy zaktualizowałem Xcode do 11.4, nagle kolor tytułu zmienił się na czarny, wcześniej był biały

if #available(iOS 13.0, *) {
        let appearance = UINavigationBarAppearance()
        appearance.configureWithOpaqueBackground()
        appearance.backgroundColor = hexStringToUIColor(hex: "#7DB52F")
        appearance.titleTextAttributes = [
            NSAttributedString.Key.foregroundColor: UIColor.white
        ]

        let buttonAppearance = UIBarButtonItemAppearance()
        buttonAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.white]
        appearance.buttonAppearance = buttonAppearance

        UINavigationBar.appearance().standardAppearance = appearance
        UINavigationBar.appearance().scrollEdgeAppearance = appearance
        UINavigationBar.appearance().compactAppearance = appearance

        UIBarButtonItem.appearance().tintColor = UIColor.white
    } else {
        UINavigationBar.appearance().barTintColor = hexStringToUIColor(hex: "#7DB52F")
        UINavigationBar.appearance().titleTextAttributes = [
            NSAttributedString.Key.foregroundColor: UIColor.white
        ]
        UINavigationBar.appearance().tintColor = UIColor.white

        UIBarButtonItem.appearance().tintColor = UIColor.white
    }
0
Priyanka Kadam 2 kwiecień 2020, 13:49