7

I would like to have a bottom toolbar with SwiftUI. The following is working in iOS 15, but not in iOS 16. In iOS 16 the toolbar is not showing. (It's working if I change the placement...)

Text("Content")
    .toolbar {
        ToolbarItemGroup(placement: .bottomBar) {
            Button("Greeting") { 
                print("Hello world!")
            }
        }
    }

Screenshots

Do you have any workaround for this?

Thanks!

Maxime
  • 73
  • 1
  • 5

3 Answers3

10

toolbar depends on the navigation bar so you have to have a NavigationView/NavigationStack

https://developer.apple.com/documentation/swiftui/view/toolbar(content:)-5w0tj

struct ToolbarSolutionView: View {
    var body: some View {
        NavigationView{ //NavigationStack
            Text("Content")
            
                .toolbar {
                    ToolbarItemGroup(placement: .bottomBar) {
                        Button("Greeting") {
                            print("Hello world!")
                        }
                    }
                }
        }
    }
}

It was likely a bug that it was working before.

You can hide the navigation bar if you don't need it.

//iOS 13+
.navigationBarHidden(true)

//iOS 16+
.toolbar(.hidden, for: .navigationBar)
lorem ipsum
  • 21,175
  • 5
  • 24
  • 48
1

For me, any conditional bottomBar does not get displayed at all, even if showTB == true on iOS 16.

  .toolbar {
    ToolbarItem(placement: .bottomBar) {
      if showTB {
        Button("Delete") {
          print(234)
        }
      }
    }
  }

Testing on the iOS 16.1 Beta, it seems to be fixed for iOS 16.1 though.

Nicolas Degen
  • 1,522
  • 2
  • 15
  • 24
  • 1
    Probably I have similar issue, however I use 2 toolbar items – `.bottomBar` and `.keyboard`. When I use conditional in `.bottomBar`, `.keyboard` toolbar doesn't display at all. And I found what is causing this issue: it's working as expected using `NavigationView` but not with `NavigationStack`. Haven't tested it on iOS 16.1 yet. – Ryba Oct 21 '22 at 06:42
1

I got the same issue. It is resolved after updating to iOS 16.1.

Howard S
  • 111
  • 5