Swift version: 5.6
If you’re using UITabBarController
to display a tab strip at the bottom of your user interface, the default behavior for iOS is to display the tabs at all times – even if the user has navigated deep into a UINavigationController
in one of the tabs.
If you don’t want that behavior, you should set hidesBottomBarWhenPushed
to true where applicable. This will hide the tab bar along with any toolbars you had showing, but only when a view controller is pushed onto the navigation stack. This allows you to show the tab bar at first, then hide it when you need more room.
If you’re using segues, the best place to set this property is inside the prepare(for:)
method, where you configure any other properties in your destination view controller:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
self.hidesBottomBarWhenPushed = true
}
If you aren’t using segues, you will usually need to override the initializer for your view controller and set hidesBottomBarWhenPushed
to true there, like this:
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
hidesBottomBarWhenPushed = true
}
SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Available from iOS 5.0
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.
Link copied to your pasteboard.