Skip to content

Instantly share code, notes, and snippets.

@johnny77221
Created December 24, 2021 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnny77221/2a8e369e0bdfa98f89ef04b361613547 to your computer and use it in GitHub Desktop.
Save johnny77221/2a8e369e0bdfa98f89ef04b361613547 to your computer and use it in GitHub Desktop.
Xcode 13 Navigation Bar not full height with Safe Area problem
let splashVC = SplashViewController()
let nav = UINavigationController(rootViewController: splashVC)
nav.navigationBar.barStyle = .blackOpaque
nav.navigationBar.isTranslucent = false
// nav.isNavigationBarHidden = true
nav.navigationBar.tintColor = .white
let navBar = nav.navigationBar
if #available(iOS 13.0, *) {
let standardAppearance = UINavigationBarAppearance()
standardAppearance.configureWithOpaqueBackground()
standardAppearance.backgroundColor = navBarColor
var standardAttr = standardAppearance.titleTextAttributes
standardAttr[NSAttributedString.Key.foregroundColor] = UIColor.white
standardAppearance.titleTextAttributes = standardAttr
let compactAppearance = standardAppearance.copy()
compactAppearance.backgroundColor = navBarColor
var compactAttr = compactAppearance.titleTextAttributes
compactAttr[NSAttributedString.Key.foregroundColor] = UIColor.white
compactAppearance.titleTextAttributes = compactAttr
navBar.standardAppearance = standardAppearance
navBar.scrollEdgeAppearance = standardAppearance
navBar.compactAppearance = compactAppearance
if #available(iOS 15.0, *) {
navBar.compactScrollEdgeAppearance = compactAppearance
}
} else {
nav.navigationBar.barTintColor = navBarColor
nav.navigationBar.backgroundColor = navBarColor
}
window!.rootViewController = nav
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment