Generic Instance Method

navigationBarTitle(_:)

Sets the title of this view’s navigation bar with a string.

Declaration

func navigationBarTitle<S>(_ title: S) -> some View where S : StringProtocol

Parameters

title

A title for this view to display in the navigation bar.

Discussion

Use navigationBarTitle(_:) to set the title of the navigation bar using a String. This modifier only takes effect when this view is inside of and visible within a NavigationView.

In the example below, text for the navigation bar title is provided using a string to provide its text.

struct FlavorView: View {
    let items = ["Chocolate", "Vanilla", "Strawberry", "Mint Chip",
                 "Pistachio"]
    let text = "Today's Flavors"
    var body: some View {
        NavigationView {
            List(items, id: \.self) {
                Text($0)
            }
            .navigationBarTitle(text)
        }
    }
}

See Also

Configuring Navigation and Status Bar Views

func navigationBarTitle(Text) -> View

Sets the title in the navigation bar for this view.

func navigationBarTitle(Text, displayMode: NavigationBarItem.TitleDisplayMode) -> View

Sets the title and display mode in the navigation bar for this view.

func navigationBarTitle(LocalizedStringKey) -> View

Sets the title of this view’s navigation bar with a localized string.

func navigationBarTitle(LocalizedStringKey, displayMode: NavigationBarItem.TitleDisplayMode) -> View

Sets the title and display mode in the navigation bar for this view.

func navigationBarHidden(Bool) -> View

Hides the navigation bar for the view.

func statusBar(hidden: Bool) -> View

Sets the visibility of the status bar.