---
title: WindowVisibilityToggle
framework: swiftui
role: symbol
role_heading: Structure
path: swiftui/windowvisibilitytoggle
---

# WindowVisibilityToggle

A specialized button for toggling the visibility of a window.

## Declaration

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

## Overview

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:)](swiftui/windowvisibilitytoggle/init(windowid:).md)

### Supporting types

- [DefaultWindowVisibilityToggleLabel](swiftui/defaultwindowvisibilitytogglelabel.md)

## Relationships

### Conforms To

- [View](swiftui/view.md)

## See Also

### Configuring window visibility

- [defaultLaunchBehavior(_:)](swiftui/scene/defaultlaunchbehavior(_:).md)
- [restorationBehavior(_:)](swiftui/scene/restorationbehavior(_:).md)
- [SceneLaunchBehavior](swiftui/scenelaunchbehavior.md)
- [SceneRestorationBehavior](swiftui/scenerestorationbehavior.md)
- [persistentSystemOverlays(_:)](swiftui/scene/persistentsystemoverlays(_:).md)
- [windowToolbarFullScreenVisibility(_:)](swiftui/view/windowtoolbarfullscreenvisibility(_:).md)
- [WindowToolbarFullScreenVisibility](swiftui/windowtoolbarfullscreenvisibility.md)
