Created
December 24, 2021 16:56
-
-
Save johnny77221/2a8e369e0bdfa98f89ef04b361613547 to your computer and use it in GitHub Desktop.
Xcode 13 Navigation Bar not full height with Safe Area problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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