<!--
{
  "availability" : [
    "macOS: 15.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/WindowVisibilityToggle",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI22WindowVisibilityToggleV"
  },
  "title" : "WindowVisibilityToggle"
}
-->

# WindowVisibilityToggle

A specialized button for toggling the visibility of a window.

```
nonisolated struct WindowVisibilityToggle<Label> where Label : View
```

## Overview

This is most commonly used in the main menu, where it can toggle the
visibility of `Window` and `UtilityWindow` windows. The default
label uses the title of the window in the format of “Show ”
and “Hide ” depending on the current visibility of the window.

A keyboard shortcut can be assigned to this button.

The below example demonstrates how a main menu can be constructed with
visibility buttons, replacing the default commands added by `Window` and
`Utility Window`:

```
 struct PhotoEditor: App {
     var body: some Scene {
         WindowGroup {
             PhotoEditor()
         }
         .commands {
            CommandGroup(before: .textFormatting) {
                Section {
                    WindowVisibilityToggle(windowID: "formatting")
                        .keyboardShortcut("t", modifiers: [.command, .shift])

                    // other custom/image formatting controls
                }
            }
            CommandGroup(before: .sidebar) {
                Section {
                    WindowVisibilityToggle(windowID: "photo-library")

                    // other controls for showing/hiding UI
                }
            }
         }

         UtilityWindow("Formatting Style", id: "formatting") {
             TextAndImageFormatForm()
         }
         .commandsRemoved()

         Window("Photo Library", id: "photo-library") {
             PhotoInfoViewer()
         }
         .commandsRemoved()
     }
 }
```

## Topics

### Creating a window visibility toggle

[`init(windowID: String)`](/documentation/SwiftUI/WindowVisibilityToggle/init(windowID:))

Create a window visibility toggle to alter the visibility of a specific
window.

### Supporting types

[`struct DefaultWindowVisibilityToggleLabel`](/documentation/SwiftUI/DefaultWindowVisibilityToggleLabel)

The default label of a window visibility toggle.

## Relationships

### Conforms To

[`View`](/documentation/SwiftUI/View)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)