Contents

navigationBarItems(trailing:)

Configures the navigation bar items for this view.

Declaration

nonisolated func navigationBarItems<T>(trailing: T) -> some View where T : View

Parameters

  • trailing:

    A view shown on the trailing edge of the title.

Discussion

Use navigationBarItems(trailing:) to add navigation bar items to the trailing edge of the navigation bar for this view. This modifier only takes effect when this view is inside of and visible within a NavigationView.

The example below adds buttons to the trailing edge of the button area of the navigation view:

struct FlavorView: View {
    var body: some View {
        NavigationView {
            List {
                Text("Chocolate")
                Text("Vanilla")
                Text("Strawberry")
            }
            .navigationBarTitle(Text("Today‘s Flavors"))
            .navigationBarItems(trailing:
                HStack {
                    Button("Hours") {
                        print("Hours tapped!")
                    }

                    Button("Help") {
                        print("Help tapped!")
                    }
                }
            )
        }
    }
}

See Also

Auxiliary view modifiers