我正在 macOS 上使用 React Native 编写一个应用程序。默认情况下,窗口显示如下:
我已经设法隐藏标题并使标题栏透明,这样(忽略屏幕截图中的标题):
我现在想向下移动“交通灯”/设置工具栏样式以匹配如下所示的样式:
不幸的是,我似乎无法弄清楚执行此操作所需的设置组合等。
我被迫扩展 objective-c AppDelegate 实现。我有当前的代码;
- (void)applicationWillBecomeActive:(NSNotification *)notification
{
NSWindow *window = [[NSApplication sharedApplication] mainWindow];
window.titleVisibility = NSWindowTitleHidden;
window.titlebarAppearsTransparent = true;
window.styleMask |= NSWindowStyleMaskFullSizeContentView;
}
这有助于进入第二阶段。我尝试过诸如;
之类的变体- (void)applicationWillBecomeActive:(NSNotification *)notification
{
NSWindow *window = [[NSApplication sharedApplication] mainWindow];
window.titleVisibility = NSWindowTitleHidden;
window.titlebarAppearsTransparent = true;
window.styleMask |= NSWindowStyleMaskFullSizeContentView;
NSToolbar *toolbar = [NSToolbar init];
window.toolbar = toolbar;
}
或
- (void)applicationWillBecomeActive:(NSNotification *)notification
{
NSWindow *window = [[NSApplication sharedApplication] mainWindow];
window.titleVisibility = NSWindowTitleHidden;
window.titlebarAppearsTransparent = true;
window.styleMask |= NSWindowStyleMaskFullSizeContentView;
window.toolbarStyle = NSWindowToolbarStyleUnified;
}
以及
toolbarStyle
的其他变体,都无济于事。
以下代码对我有用:
- (void)applicationWillBecomeActive:(NSNotification *)notification
{
NSWindow *window = [[[NSApplication sharedApplication] windows] firstObject];
window.titleVisibility = NSWindowTitleHidden;
window.titlebarAppearsTransparent = true;
window.styleMask |= NSWindowStyleMaskFullSizeContentView;
window.toolbar = [NSToolbar new]; // <-- Note this is `new` and not `init`
window.toolbarStyle = NSWindowToolbarStyleUnified;
}