Post

Replies

Boosts

Views

Activity

Reply to Fixed MacOS App Windows / Sizing Windows
Thanks to chatGPT ... I'll post the finished basic structure for the window here. It's technically the window you see when you click on the Apple logo to open the “About this Mac” function .... @main struct FixedSizeWindowApp: App { @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate var body: some Scene { WindowGroup { EmptyView() // No additional content required as the window is managed by AppDelegate } } } class AppDelegate: NSObject, NSApplicationDelegate { var window: NSWindow! func applicationDidFinishLaunching(_ notification: Notification) { // Create Window let windowRect = NSRect(x: 0, y: 0, width: 1600, height: 1000) window = NSWindow( contentRect: windowRect, styleMask: [.titled, .closable], // Title bar and close button backing: .buffered, defer: false ) // Window properties window.center() // Center window window.title = "About this Mac" // Set title window.isReleasedWhenClosed = false // Keep window window.isMovableByWindowBackground = true // Movable window // Fixed window size window.minSize = windowRect.size window.maxSize = windowRect.size // Contents of the window with SwiftUI let hostingView = NSHostingView(rootView: ContentView()) hostingView.frame = window.contentView!.bounds hostingView.autoresizingMask = [.width, .height] window.contentView = hostingView // Show Window window.makeKeyAndOrderFront(nil) } func applicationWillTerminate(_ notification: Notification) { // Insert cleanup functions etc. } } struct ContentView: View { var body: some View { VStack { Image(systemName: "applelogo") .font(.system(size: 50)) .padding() Text("About this Mac") .font(.title) .bold() Spacer() } .frame(maxWidth: .infinity, maxHeight: .infinity) } } Happy holidays, Oliver
2w