'hide navigation bar in iOS13 + xcode 11
I want to hide the navigationBar for the first ViewController which is my first screen. It's all embedded within a navigation controller. I tried the below code but not working.
override func viewWillAppear(_ animated: Bool) {
let navigationBar = navigationController?.navigationBar
if #available(iOS 13.0, *) {
let navigationBarAppearence = UINavigationBarAppearance()
navigationBarAppearence.shadowColor = .clear
navigationBar?.scrollEdgeAppearance = navigationBarAppearence
navigationBar?.standardAppearance = navigationBarAppearence
navigationBar?.compactAppearance = navigationBarAppearence
navigationBar?.backgroundColor = .clear
navigationBar?.isHidden = true
} else {
navigationBar?.isHidden = true
}
}
I'm using xcode11 How can I hide the navigation bar? Suggestions are always appreciated.
Solution 1:[1]
try this code
self.navigationController?.isNavigationBarHidden = true
Solution 2:[2]
Try this
navigationController?.isNavigationBarHidden = true
instead of
let navigationBar = navigationController?.navigationBar
navigationBar?.isHidden = true
Solution 3:[3]
I know you tried with coding but try something different. Without code, you can use Main.storyboard.
1.Press on your "Navigation Controller Scene" 2.Press "Navigation Controller" 3.Your side bar to your righthand side (forgot what its called) 4.Hover over the top icons to find "show the Attributes inspector" 5.After find under the "Simulated Metric" is the "Navigation Controller" 6.Next to "Bar Visbilty" unclick "Shows Navigation Bar" 7.All done
I know it is not code but hope this works for you.
Solution 4:[4]
hide navigation bar for in iOS15 + xcode 13
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if #available(iOS 15, *) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.titleTextAttributes = [.foregroundColor: UIColor.white]
appearance.backgroundColor = UIColor(red: 0.0/255.0, green: 125/255.0, blue: 0.0/255.0, alpha: 1.0)
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
}
Solution 5:[5]
You need to hide in each view controller. This code can help you.
// Hide navBar when view controller appear
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: animated)
}
// Show navBar again when view controller disappear
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(false, animated: animated)
}
Note: You need to display the navBar again when disappear, because if you set this setting in one view controller, all other view controllers will be affected.
Tested with XCode Version 13.3.1 (13E500a) and iOS 15.1 (19B74) on iPhone 6s.
Solution 6:[6]
Use ViewController's viewDidLayoutSubviews method to hide/show the navigationbar.
FirstViewController
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.navigationController?.setNavigationBarHidden(true, animated: true)
}
SocondViewController
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.navigationController?.setNavigationBarHidden(false, animated: true)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | vishnu anilkumar |
| Solution 2 | Faysal Ahmed |
| Solution 3 | WereWolf12 |
| Solution 4 | |
| Solution 5 | Wo_0NDeR |
| Solution 6 | Kishan Raiyani |


