如何从另一个ViewController更改MacOS应用程序的菜单栏图标?
我发现了这个,但这并没有改变我的菜单栏图标: Mac: How to save alternate app icon in dock OSX xcode
let image = NSImage.init(named: NSImage.Name(rawValue: "AltAppIcon"))
NSApp.applicationIconImage = image
看看BOINC图标的菜单栏右下方如何显示小自定义暂停符号/徽章?此应用程序的图标更改。他们是在覆盖该文件的名称并将其更改为“已暂停的图标”图片吗?
✅更新*
设置菜单栏图标的AppDelegate.swift
函数起作用:
AppDelegate.swift
func setIcon() {
let onIcon = NSImage(named: "fv-mini-icon-green")
statusItem.button?.image = onIcon
}
ViewController.swift
func taskOnIcon() {
DispatchQueue.main.async(execute: {
let appDele = NSApplication.shared.delegate as! AppDelegate
appDele.setIcon()
})
}
答案 0 :(得分:1)
这是一种方法...
class AppDelegate: NSObject, NSApplicationDelegate {
var statusBarItem: NSStatusItem!
func applicationDidFinishLaunching(_ aNotification: Notification) {
let statusBar = NSStatusBar.system
statusBarItem = statusBar.statusItem(withLength: 16)
let button = statusBarItem.button
button?.image = NSImage(named: "fv-mini-icon-green")
// .. other code here