Jesus
Jesus

Reputation: 8586

how to begin NSWindow in fullscreen

I am developing an app for Mac OSX in Xcode5

and I want to display my first Window in fullscreen (no toolbar just my view)

I found a way to display a button on the corner for fullscreen:

AppDelegate.m:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    screenFrame = [[NSScreen mainScreen] frame];

    [self.window setBackgroundColor: NSColor.whiteColor];
    [self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
    [[self window] setFrame:screenFrame display:YES];
}

but to get fullscreen I have to click on the corner's button

enter image description here

how to get fullscreen saving the step of pressing that button?

Upvotes: 5

Views: 7371

Answers (2)

BackSpace
BackSpace

Reputation: 119

Swift Version:

let screenFrame = NSScreen.main?.frame
self.window?.collectionBehavior = NSWindow.CollectionBehavior.fullScreenPrimary
self.window?.setFrame(screenFrame!, display: true)
self.window?.toggleFullScreen(self)

Upvotes: 5

Jesús Ayala
Jesús Ayala

Reputation: 2791

add this [self.window toggleFullScreen:self];

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    screenFrame = [[NSScreen mainScreen] frame];

    [self.window setBackgroundColor: NSColor.whiteColor];
    [self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
    [self.window setFrame:screenFrame display:YES];
    [self.window toggleFullScreen:self];
}

Upvotes: 11

Related Questions