Search code examples
swiftswiftuiswiftui-navigationview

when placing items in the toolbar, How do you remove the space where a navigation title would go


I've created a sample project that has a toolbar with text. All of my content has a space above it where a navigation title would go if I had one. I would like to remove this space. Here's my sample project:

NavigationView {
    VStack(spacing: 0) {
        List {
            ForEach((1...50), id: \.self) {
                Text("\($0)…")
            }
        }
    }.toolbar {
        Text("Hello World!")
    }
} 

Solution

  • putting .navigationBarTitleDisplayMode(.inline) on the VStack fixes this issue. (credit: ChrisR for the comment)