Изменить цвет заголовка Swift - PullRequest
0 голосов
/ 02 апреля 2020
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white]

Я поместил приведенный выше код в файл AppDelegate, цвет заголовка по-прежнему черный.

Ответы [ 3 ]

1 голос
/ 02 апреля 2020

Вы можете попробовать это:

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
}
0 голосов
/ 02 апреля 2020

Выше проблема возникла, когда я обновил свой XCode до 11.4, внезапно цвет заголовка изменился на черный, ранее он был белым

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 голосов
/ 02 апреля 2020

Попробуйте,

let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.red]
        UINavigationBar.appearance().titleTextAttributes = textAttributes
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...