如何禁用或洗掉 SwiftUI macOS 應用程式中的選單項?例如,該Print...專案File默認顯示在選單中。但我的應用程式不使用列印功能。如何從 SwiftUI Mac 應用程式的檔案選單中洗掉列印項?

我嘗試了以下方法,AppDelegate.swift但它不起作用:
import Cocoa
import SwiftUI
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationWillFinishLaunching(_ notification: Notification) {
if let menu = NSApplication.shared.mainMenu {
menu.item(withTitle: "File")?.submenu?.item(withTitle: "Print...")?.state = NSControl.StateValue.off
}
}
}
uj5u.com熱心網友回復:
[每個請求@Alexander]
早期的 SwiftUI 專案模板具有主選單Main.storyboard(或 xib 檔案)的顯式資源。如果你能在你的專案中找到一個,那么只需在那里找到選單并手動洗掉列印選單項。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/407174.html
標籤:
上一篇:哪個目錄最適合保存日志?
