【发布时间】:2023-03-23 20:53:01
【问题描述】:
我有一个带有 AppDelegate 的简单 SwfitUI(XCode 12.4、MacOS 11.1)Mac 应用程序。
如何删除默认的文件/编辑/查看/窗口/帮助菜单并用自定义菜单替换它们?
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
let _ = NSApplication.shared.windows.map { $0.tabbingMode = .disallowed }
let mainWindow = NSApplication.shared.windows.first!
mainWindow.backgroundColor = NSColor(red: 1, green: 1, blue: 1, alpha: 0.3)
mainWindow.titlebarAppearsTransparent = true
mainWindow.titleVisibility = .hidden
mainWindow.backgroundColor = NSColor(red: 1, green: 1, blue: 1, alpha: 1)
}
func applicationWillFinishLaunching(_ notification: Notification) {
NSWindow.allowsAutomaticWindowTabbing = false
}
}
@main
struct VeyBoardApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
【问题讨论】:
-
在我看来你不应该这样做,我们 Mac 用户希望每个程序都有这些菜单