我想在 Swift 中获取
main NSMenu
以执行以下代码 NSMenu(title: "ApplicationName").autoenablesItems = false
。我不知道插入什么作为title
,因为它似乎无法获得对它的引用并禁用autoenablesItems
,因为我无法设置MenuItem
的enabled
-Property。
只是一个简短的评论,希望它能帮助其他有同样问题的人。这道题的答案是将storyboard中自动创建的主菜单或菜单项添加到appDelegate中,并创建相关代码
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var saveMenuItem: NSMenuItem! // Can be added by dragging from the storyboard
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
}