modemlooper avatar
About Blog

Close button in SwiftUI modals - iOS 26

2 min read
swiftui ios26 tips

Apple’s SwiftUI framework in iOS 26 adds a close button role specifically meant for dismissing informational displays like modals or sheets that contain read-only information.

This differs from the cancel role that already exists—cancel suggests you’re discarding changes or stopping something in progress, while close simply means you’re done viewing content without any data being lost. The close role doesn’t trigger dismissal on its own, but it tells SwiftUI what the button is for, which helps with things like accessibility features and keeping the interface consistent across platforms.

You could implement it in a modal sheet like this:

struct CustomSheet: View {
    @Environment(\.dismiss) private var dismiss

    var body: some View {
        NavigationStack {
            CustomView()
                .toolbar {
                    Button(role: .close) {
                        dismiss()
                    }
                }
        }
    }
}

This creates a standard system close button that includes an xmark icon automatically—no need to manually specify the label or symbol yourself. It’s a minor enhancement, but it helps keep your SwiftUI modals consistent with how the platform typically handles these interactions.