NSWindow-Levels

A small example on using NSWindow.Level in SwiftUI on MacOS

alt text

Instructions

  1. Download & compile
  2. Run!
    • To change levels, select one and refresh!
    • To visit Apple’s documentation, press the “documentation” button!

Do It Yourself!

Maybe you don’t want to download the project. That’s fine! Here’s a minimal example:

func setLevel(level: NSWindow.Level) {
    for window in NSApplication.shared.windows {
        window.level = level
    }
}

This is a function that you can put in the app you’re making. The available values for the “level” variable in the function are:

.normal
.floating
.submenu
.tornOffMenu
.mainMenu
.statusBar
.modalPanel
.popUpMenu
.screenSaver

Additionally, you can use NSWindow.Level(rawValue: NSWindow.Level.normal.rawValue - 1) to make the window always stay below other windows.

Sources

Thank you very much to those who made/answered these sources!

GitHub

View Github