Swift 全局更改使用外观代理的UINavigationBar背景无效
我正在尝试使用UINavigationBarAppearance更改应用程序中所有UINavigationBar的某些属性。我正在调用AppDelegate.swift中的Swift 全局更改使用外观代理的UINavigationBar背景无效,swift,uikit,ios13,Swift,Uikit,Ios13,我正在尝试使用UINavigationBarAppearance更改应用程序中所有UINavigationBar的某些属性。我正在调用AppDelegate.swift中的应用程序(uquot:didfishlaunchingwithoptions:)中的以下函数: func customizeAppearance() { let navBarAppearance = UINavigationBarAppearance() navBarAppearance.configureW
应用程序(uquot:didfishlaunchingwithoptions:)
中的以下函数:
func customizeAppearance() {
let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.configureWithDefaultBackground()
navBarAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
navBarAppearance.backgroundColor = UIColor.black
UITabBar.appearance().backgroundColor = UIColor.black
let tintColor = UIColor(red: 255/255.0, green: 238/255.0, blue: 136/255.0, alpha: 1.0)
UITabBar.appearance().tintColor = tintColor
}
我希望这会改变背景颜色和标题文本的颜色,但当我运行应用程序时,只有文本颜色会改变(UITabBar也是如此)。有什么建议吗?您应该在UINavigationController中使用此
UINavigationBarAppearance
。如果对UINavigationController使用全局外观,则应使用UINavigationBar.appearance()
而不是UINavigationBarAppearance()
Hmm.UINavigationBar.appearance()似乎不提供对TitleExtAttributes属性的访问。出于某种原因,XCode不会自动完成UINavigationBar.appearance().barTintColor或UINavigationBar.appearance().titleTextAttributes。我不确定这是为什么,但如果我把它打印出来,它会像预期的那样工作。谢谢