skip to Main Content

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!

3

Answers


  1. 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)
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. I got the same issue. It is resolved after updating to iOS 16.1.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search