Home > Back-end >  Toolbar bottom iOS 16 - SwiftUI
Toolbar bottom iOS 16 - SwiftUI

Time:09-14

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!

CodePudding user response:

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)
  • Related