How do I make a SwiftUI view fullscreen running Mac OS, Catalina or Big Sur?
SwiftUI Fullscreen Mac os
Add a Comment
Code Block // start App in fullScreen mode
let mainScreen: NSScreen = NSScreen.screens[0]Is there a way to do this in SwiftUI?
This seems a partial answer to the question: https://stackoverflow.com/questions/23896803/os-x-detecting-when-front-app-goes-into-fullscreen-mode
For a SwiftUI macOS App, I came up with this solution to enter full screen. In my use case I want the app to go full screen immediately on launch, but you can do this at any point.
import SwiftUI
@main
struct MacApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onAppear {
DispatchQueue.main.asyncAfter(0.1) {
if let window = NSApplication.shared.windows.last {
window.toggleFullScreen(nil)
}
}
}
}
}
}