How do I make a toolbar-style window ornament from UIKit?

I've got a UIKit app and I want to add some buttons in a top-edge window ornament. I'm looking at the WWDC23 talk Meet UIKit for Spatial Computing, and it does exactly what I think I want to do:

extension EditorViewController {

    func showEditingControlsOrnament() {
        let ornament = UIHostingOrnament(sceneAlignment: .bottom, contentAlignment: .center) {
            EditingControlsView(model: controlsViewModel)
                .glassBackgroundEffect()
        }

        self.ornaments = [ornament]

        editorView.style = .edgeToEdge
    }
}

But the thing I really want to know is what is in EditingControlsView. Is it a toolbar? How do you make a toolbar in SwiftUI without something to attach the .toolbar modifier to?

Answered by Vision Pro Engineer in 810347022

Hi @Mr. Jefferson,

EditingControlsView contains the buttons that you'd like to add in the ornament. For instance, it would look something like this:

struct CustomOrnamentBar: View {
    var body: some View {
        HStack {
            Button {
                //do something
            } label: {
                Image(systemName: "trash")
            }
            
            Button {
                // do something
            } label: {
                Image(systemName: "square.and.arrow.up")
            }
        }
    }
}
Accepted Answer

Hi @Mr. Jefferson,

EditingControlsView contains the buttons that you'd like to add in the ornament. For instance, it would look something like this:

struct CustomOrnamentBar: View {
    var body: some View {
        HStack {
            Button {
                //do something
            } label: {
                Image(systemName: "trash")
            }
            
            Button {
                // do something
            } label: {
                Image(systemName: "square.and.arrow.up")
            }
        }
    }
}
How do I make a toolbar-style window ornament from UIKit?
 
 
Q