从 ViewController 设置菜单栏图标
Set menubar icon from ViewController
如何更改另一个 MacOS 应用程序的菜单栏图标ViewController?
- AppDelegate.swift(初始化菜单栏图标)
- ViewController.swift(尝试设置菜单栏图标❌)
我找到了这个,但这并没有改变我的菜单栏图标:
let image = NSImage.init(named: NSImage.Name(rawValue: "AltAppIcon"))
NSApp.applicationIconImage = image
看到 BOINC 图标如何在其菜单栏的右下方有自定义的小暂停 symbol/badge 了吗?这个应用程序的图标改变了。他们是否改写了该文件的名称并将其更改为 "paused icon" 图像?
✅更新*
设置菜单栏图标的 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()
})
}
这里有一个方法...
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
如何更改另一个 MacOS 应用程序的菜单栏图标ViewController?
- AppDelegate.swift(初始化菜单栏图标)
- ViewController.swift(尝试设置菜单栏图标❌)
我找到了这个,但这并没有改变我的菜单栏图标:
let image = NSImage.init(named: NSImage.Name(rawValue: "AltAppIcon"))
NSApp.applicationIconImage = image
看到 BOINC 图标如何在其菜单栏的右下方有自定义的小暂停 symbol/badge 了吗?这个应用程序的图标改变了。他们是否改写了该文件的名称并将其更改为 "paused icon" 图像?
✅更新*
设置菜单栏图标的 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()
})
}
这里有一个方法...
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