Xcode & Swift - Window without title bar but with close, minimize and resize buttons

后端 未结 7 2171
被撕碎了的回忆
被撕碎了的回忆 2020-12-22 17:29

I am currently using Swift in Xcode 6, Beta 5. I am trying to remove the title bar, or any visible difference between the title bar and the actual content. If I enable \"Uni

相关标签:
7条回答
  • 2020-12-22 17:50

    You can use these:

    override func viewDidAppear() {
        super.viewDidAppear()
    
        self.view.window?.titlebarAppearsTransparent = true
        self.view.window?.movableByWindowBackground = true
    }
    
    0 讨论(0)
  • 2020-12-22 17:58

    Since MacOS X 10.10, you can use these:

    if #available(macOS 10.10, *) {
        window.titlebarAppearsTransparent = true
    }
    
    if #available(macOS 10.2, *) {
        window.movableByWindowBackground  = true
    }
    

    There was an official sample project for window appearance in Yosemite. You might wanna check it out.

    0 讨论(0)
  • 2020-12-22 18:00

    I don't have enough reputation to comment on Ranfei Songs answer, but running on OSX 10.12 the syntax for the titleVisibility is slightly different, instead of this:

    self.window.titleVisibility = NSWindowTitleVisibility.Hidden;
    

    you'll need to use NSWindowTitleHidden instead, so updating Ranfei's code would result in you need to specify this like this:

    self.window.titleVisibility = NSWindowTitleHidden;
    self.window.titlebarAppearsTransparent = YES;
    self.window.styleMask |= NSFullSizeContentViewWindowMask;
    
    0 讨论(0)
  • 2020-12-22 18:06

    The new window style mask NSFullSizeContentViewWindowMask added in OS X 10.10 will do the trick.

    self.window.titleVisibility = NSWindowTitleVisibility.Hidden;
    self.window.titlebarAppearsTransparent = YES;
    self.window.styleMask |= NSFullSizeContentViewWindowMask;
    

    Release Notes

    0 讨论(0)
  • 2020-12-22 18:06

    For Swift 3 :-

    self.window.titleVisibility = .hidden
    self.window.titlebarAppearsTransparent = true
    self.window.styleMask.insert(.fullSizeContentView)
    
    0 讨论(0)
  • 2020-12-22 18:14

    If you are using storyboard, it's just a simple check box in the Inspector bar.

    1. Select the window from Story Board

    2. Check the Transparent Title Bar checkbox in the inspector window.

    Here's how it looks like in the Story board. It looks the same when you build and run the application.

    0 讨论(0)
提交回复
热议问题