应用以下代码来更新导航栏的外观。如果您希望在整个应用程序中使用相同的外观,则可以在AppDelegate中完成此操作。
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: .black]
appearance.backgroundColor = .white
// Default portrait view
UINavigationBar.appearance().standardAppearance = appearance
// There are other appearances you could apply it to as well...
// UINavigationBar.appearance().scrollEdgeAppearance = appearance
// UINavigationBar.appearance().compactAppearance = appearance
像这样:
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .red
appearance.titleTextAttributes = [.font:
UIFont.boldSystemFont(ofSize: 20.0),
.foregroundColor: UIColor.white]
// Customizing our navigation bar
navigationController?.navigationBar.tintColor = .white
navigationController?.navigationBar.standardAppearance = appearance
navigationController?.navigationBar.scrollEdgeAppearance = appearance
我写了一篇新文章谈论它。
https://medium.com/@eduardosanti/uinavigationbar-is-black-on-ios-15-44e7852ea6f7