'SwiftUI and NavigationBar
I have a large iOS app with swift and XIBs for the view controllers. Now I'm progressively migrating from XIBs/View controllers to SwiftUI but I don't know how to solve a specific problem.
Some XIB/View controllers have a navigation bar, if these XIB/controllers push a SwiftUI view the SwiftUI view appears correctly with its content and the navigation bar inherited from its parent XIB view. But some of the SwiftUI views need to change some of the inherited navigation bar buttons and I don't know how to access from the SwiftUI code to the navigation bar content.
I tried to hide the inherited navigation bar using
.navigationBarTitle("")
.navigationBarHidden(true)
(which is working) and creating a SwiftUI navigationbar using NavigationView component, but:
I don't know if this is the correct approach.
Using this NavigationView component the new navigation bar shown is much higher than the inherited navigation bar. Why is it showing a much higher navbar? Could I change this heght and how?
Thank you!
Solution 1:[1]
Well, I've just discovered that I have this method:
.navigationBarItems(leading: View, trailing: View)
So I can customize my navbar buttons with it. I don't need to hide the inherited navbar, just customize it.
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 | Wonton |
