I am looking to be able to use a NavigationButton
to navigate to a new view within .navigationBarItems
. This is how I expect it should work:
NavigationView {
Text("Hello world")
.navigationBarTitle(Text("Title"))
.navigationBarItems(trailing:
NavigationButton(destination: TestView()) {
Text("Next")
}
)
}
However, the "Next" button doesn't do anything! I am aware of PresentationButton which provides a popover view like so:
NavigationView {
Text("Hello world")
.navigationBarTitle(Text("Title"))
.navigationBarItems(trailing:
PresentationButton(destination: TestView()) {
Text("Next")
}
)
}
But this isn't what I'm looking for.
To change a navigation bar color in SwiftUI, you apply toolbarBackground modifier to the content view of NavigationStack . NavigationView is deprecated in iOS 16. toolbarBackground accepts two parameters. ShapeStyle : The style to display as the background of the bar.
As I told you in comments, It was a bug. But it get fixed and it's working now exactly as you expected since Beta 5, But remember, NavigationButton
has changed to NavigationLink
. So it would be like:
struct ContentView: View {
var body: some View{
NavigationView {
Text("Hello world")
.navigationBarTitle(Text("Title"))
.navigationBarItems(trailing:
NavigationLink(destination: TestView()) {
Text("Next")
}
)
}
}
}
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