I have three view controllers that I want to have the same navigation bar on but I can't figure out a way to "share" the navbar between those three views. Is there a more efficient way to link up the nav controllers with the view controllers so that I don't have three different navigation controllers even though the navigation controllers are exactly the same?
In addition, I have a tab bar controller if that makes a difference.
Picture to clarify:
Create A SubnavUse any element to open the subnav/dropdown menu, e.g. a <button>, <a> or <p> element. Use a container element (like <div>) to create the subnav menu and add the subnav links inside it. Wrap a <div> element around the button and the <div> to position the subnav menu correctly with CSS.
As Ch0k0I8 mentioned, UIAppearance
is a good way to set a common UI theme throughout the app.
If you are looking for the same functionality between navigation controllers, then you should subclass UINavigationController
and implement the common functionality there. Then you can use your custom navigation controller in the storyboard or in code in the 3 places you wish. To put your custom subclass in the storyboard, drag a UINavigationController
onto the storyboard like you normally would, then change the class to your custom navigation controller class in the utilities tab. Here is what a custom UINavigationController
subclass might look like:
class CustomNavController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
// do whatever custom setup stuff you want here
}
// override other methods for different customizations
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With