How it works
UIHostingOrnament is a UIKit-hosted container that places SwiftUI content into an ornament — a floating accessory that visionOS positions relative to the edges of a window scene rather than inside its bounds. Use it when your interface is built in UIKit but you want to surface controls, toolbars, or status views as ornaments around a window, letting you author that floating content with SwiftUI while UIKit manages the hosting. It bridges a SwiftUI view hierarchy into the ornament slot the same way a hosting controller bridges a view into a scene, so the SwiftUI content participates in layout, state, and the system glass material that gives ornaments their distinct look. Reach for it on visionOS specifically, where ornaments are the platform's idiom for keeping affordances visible and reachable without crowding the main window.
Anchor the ornament to a scene edge
An ornament is positioned by an attachment anchor that names where, relative to the window, it should float. In the example the SwiftUI equivalent declares
attachmentAnchor: .scene(.bottom), pinning the accessory beneath theText("Main Window")window; a UIHostingOrnament exposes the same scene-relative placement so the hosted content sits along the chosen edge instead of overlapping the window content.Supply the SwiftUI content to host
The ornament's payload is an ordinary SwiftUI view hierarchy that UIHostingOrnament renders into the floating slot. Here that payload is the
HStack(spacing: 16)ofImage(systemName:)transport controls —play.fill,pause.fill, andforward.fill— which becomes the ornament's body. Any SwiftUI view works as the hosted content, so the same@Stateand layout you'd use in a normal view applies inside the ornament.Adopt the system glass material
Ornaments read as floating glass, and you get that by backing the hosted content with a system material. The example applies
.background(.thinMaterial, in: Capsule())after.padding(), giving the control cluster the translucent, vibrant capsule the platform expects of an ornament; UIHostingOrnament places this finished, materialized SwiftUI content into the scene's ornament layer.Keep the ornament outside the window bounds
Because the ornament is attached to the scene rather than composited into the window, it floats alongside
Text("Main Window")— styled with.frame(width: 220, height: 140),.background(.regularMaterial), and.clipShape(RoundedRectangle(cornerRadius: 16))— without consuming any of that window's interior space. UIHostingOrnament is the UIKit-side handle for exactly that relationship: SwiftUI content that lives next to, not inside, the scene it accompanies.
.scene(.bottom) to .scene(.top) and watch the transport-control ornament reposition from below the window to above it, demonstrating how the attachment anchor drives where the hosted content floats.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct UIHostingOrnamentDemo: View {
var body: some View {
Text("Main Window")
.font(.title)
.frame(width: 220, height: 140)
.background(.regularMaterial)
.clipShape(RoundedRectangle(cornerRadius: 16))
.ornament(attachmentAnchor: .scene(.bottom)) {
HStack(spacing: 16) {
Image(systemName: "play.fill")
Image(systemName: "pause.fill")
Image(systemName: "forward.fill")
}
.padding()
.background(.thinMaterial, in: Capsule())
}
.padding()
}
}