Skip to content

Instantly share code, notes, and snippets.

@johncodeos
Last active January 22, 2022 11:38
Show Gist options
  • Save johncodeos/32a8d6b52c0850ae0a01eaa1517a9626 to your computer and use it in GitHub Desktop.
Save johncodeos/32a8d6b52c0850ae0a01eaa1517a9626 to your computer and use it in GitHub Desktop.
Fix for the transparent/gray navigation bar in iOS 15
// For UIKit project
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Demo App"
self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.navigationBar.tintColor = .white
self.navigationController?.navigationBar.barTintColor = .red
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .red
self.navigationController?.navigationBar.standardAppearance = appearance
self.navigationController?.navigationBar.scrollEdgeAppearance = appearance
}
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
}
// For SwiftUI project
init() {
let appearance = UINavigationBarAppearance()
appearance.titleTextAttributes = [.foregroundColor: UIColor.white]
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .red
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
UINavigationBar.appearance().isTranslucent = false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment