Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 更改标题的颜色_Ios_Swift_Uinavigationcontroller - Fatal编程技术网

Ios 更改标题的颜色

Ios 更改标题的颜色,ios,swift,uinavigationcontroller,Ios,Swift,Uinavigationcontroller,我已将上述代码放在AppDelegate文件中,标题的颜色仍然是黑色。您可以尝试以下操作: UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white] 试试这个 if #available(iOS 13.0, *) { let appearance = UINavigationBarAppe

我已将上述代码放在AppDelegate文件中,标题的颜色仍然是黑色。

您可以尝试以下操作:

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

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
}

当我将Xcode更新到11.4时,出现了上述问题 突然,标题颜色变为黑色,之前是白色

let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.red]
        UINavigationBar.appearance().titleTextAttributes = textAttributes

试一试:这能回答你的问题吗?
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
    }