Hi, I have a navigation bar already set in my xcode, but whenever I try to display items it doesn’t work. How do I display items to my navigation using SwiftUI? Thanks.
Here is a code example using leading and trailing navigation bar items.
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
Text("Hello, world!")
.padding()
}
.navigationTitle("Navigation Bar")
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(
leading:
Button(action: {
print("Leading Button Tapped")
}, label: {
Image(systemName: "pause")
.padding(5)
}),
trailing:
Button(action: {
print("Trailing Button Tapped")
}, label: {
Image(systemName: "play")
.padding(5)
})
)
}
}
}
Padding has been added around the button to make the target larger otherwise the button requires pin point accuracy to get it to respond.