Prontto
Prontto

Reputation: 1681

How I can programmatically set NSWindow to full screen?

Example when you double-click Xcode's toolbar, Xcode will automatically goes full screen (still show's menubar). How I can achieve same result programmatically using storyboards and Xcode 7 GM?

Upvotes: 2

Views: 2758

Answers (3)

M Afham
M Afham

Reputation: 960

Here is the swift 5 version. In viewWillAppear() function of you view controller, call this function.

 func setWindowFrameAndCenter() {
        guard let window = self.view.window,
              let windowScreenFrame = window.screen?.visibleFrame else {
                  return
              }
        window.setFrame(windowScreenFrame,
                        display: false,
                        animate: false)
        window.center()
    }

Upvotes: 2

RichIntellect
RichIntellect

Reputation: 281

In Objective C:

[self.window setFrame:NSScreen.mainScreen.visibleFrame display: true animate: true];

Upvotes: 0

Eric Aya
Eric Aya

Reputation: 70096

This mode is not called "full screen" but "zoomed".

You can "zoom" a window to the max available space by using the NSScreen visible frame as the target frame.

Let's say window is your NSWindow IBOutlet:

window.setFrame(NSScreen.mainScreen()!.visibleFrame, display: true, animate: true)

Upvotes: 6

Related Questions