Hide NSWindow title bar

后端 未结 8 1011
萌比男神i
萌比男神i 2020-12-13 00:46

Is there a way to hide the titlebar in an NSWindow? I don\'t want to have to completely write a new custom window. I can\'t use NSBorderlessWindowMask because I have a botto

相关标签:
8条回答
  • 2020-12-13 01:26

    The only way I know would be to create a window without a titlebar (see NSBorderlessWindowMask). Note that you can't (easily) create a window without a titlebar in IB, so you will have to do a bit of work in code (there are a couple of different approaches, you can probably figure it out).

    A big drawback with using a window without a titlebar is that you're now on the hook for much more of the standard appearance and behaviour - rounded corners and such.

    0 讨论(0)
  • 2020-12-13 01:38

    I had an experience that when I first set content view of my window and then set the window borderless:

    [yourWindow setStyleMask:NSBorderlessWindowMask];
    

    Nothing would appear in my window. So i first set the style mask and after that i've set the content view:

    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    { 
        // 1. borderless window
        [[self window] setStyleMask: NSBorderlessWindowMask];
        // 2. create the master View Controller
        self.masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];
        // 3. Add the view controller to the Window's content view
        [self.window.contentView addSubview:self.masterViewController.view];
        self.masterViewController.view.frame = ((NSView*)self.window.contentView).bounds;     
    }
    

    And voila, the content of my window has appeared.

    0 讨论(0)
  • 2020-12-13 01:38

    You can use WAYInAppStoreWindow available on GitHub which works on Yosemite and Mavericks.

    0 讨论(0)
  • 2020-12-13 01:39

    Starting from OS X 10.10, you can hide title bar.

    window1.titlebarAppearsTransparent = true
    window1.titleVisibility            = .Hidden
    

    Maybe you want to override window style.

    window1.styleMask = NSResizableWindowMask
                      | NSTitledWindowMask
                      | NSFullSizeContentViewWindowMask
    
    0 讨论(0)
  • 2020-12-13 01:40

    What happens if you get the superview of the close button? Can you hide that?

    // Imagine that 'self' is the NSWindow derived class
    NSButton *miniaturizeButton = [self standardWindowButton:NSWindowMiniaturizeButton];
    NSView* titleBarView = [miniaturizeButton superview];
    [titleBarView setHidden:YES];
    
    0 讨论(0)
  • 2020-12-13 01:41
    [yourWindow setStyleMask:NSBorderlessWindowMask];
    
    0 讨论(0)
提交回复
热议问题