可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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 bottom bar on my window, and using NSBorderlessWindowMask makes that disappear. I also tried using setContentBorderThickness:forEdge: with NSMaxYEdge and setting it to 0, that didn't work either.
Any help is appreciated
回答1:
[yourWindow setStyleMask:NSBorderlessWindowMask];
回答2:
Starting from OS X 10.11, you can hide title bar.
window1.titlebarAppearsTransparent = true window1.titleVisibility = .Hidden
Maybe you want to override window style.
window1.styleMask = NSResizableWindowMask | NSTitledWindowMask | NSFullSizeContentViewWindowMask
回答3:
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];
回答4:
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.
回答5:
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.
回答6:
You can use WAYInAppStoreWindow available on GitHub which works on Yosemite and Mavericks.
回答7:
Kind of Welcome screen NSWindow / NSViewController setup (Swift 4.1)
extension NSWindow { enum Style { case welcome } convenience init(contentRect: CGRect, style: Style) { switch style { case .welcome: let styleMask: NSWindow.StyleMask = [.closable, .titled, .fullSizeContentView] self.init(contentRect: contentRect, styleMask: styleMask, backing: .buffered, defer: true) titlebarAppearsTransparent = true titleVisibility = .hidden standardWindowButton(.zoomButton)?.isHidden = true standardWindowButton(.miniaturizeButton)?.isHidden = true } } } class WelcomeWindowController: NSWindowController { private (set) lazy var viewController = WelcomeViewController() private let contentWindow: NSWindow init() { contentWindow = NSWindow(contentRect: CGRect(x: 400, y: 200, width: 800, height: 472), style: .welcome) super.init(window: contentWindow) let frameSize = contentWindow.contentRect(forFrameRect: contentWindow.frame).size viewController.view.setFrameSize(frameSize) contentWindow.contentViewController = viewController } } class WelcomeViewController: NSViewController { private lazy var contentView = View() override func loadView() { view = contentView } init() { super.init(nibName: nil, bundle: nil) } override func viewDidLoad() { super.viewDidLoad() contentView.backgroundColor = .white } } class View: NSView { var backgroundColor: NSColor? convenience init() { self.init(frame: NSRect()) } override func draw(_ dirtyRect: NSRect) { if let backgroundColor = backgroundColor { backgroundColor.setFill() dirtyRect.fill() } else { super.draw(dirtyRect) } } }
Result
