![](/img/trans.png)
[英]How to set an action to menubar icon on swipe gesture in swift/SwiftUI
[英]Set menubar icon from ViewController
如何從另一個 ViewController 更改 MacOS 應用程序的菜單欄圖標?
我發現了這個,但這並沒有改變我的菜單欄圖標: Mac:如何在 Dock OSX xcode 中保存備用應用程序圖標
let image = NSImage.init(named: NSImage.Name(rawValue: "AltAppIcon"))
NSApp.applicationIconImage = image
看看 BOINC 圖標如何在其菜單欄的右下角有一個小的自定義暫停符號/徽章? 此應用程序的圖標發生變化。 他們是否會改寫該文件的名稱並將其更改為“暫停的圖標”圖像?
✅更新*
設置菜單欄圖標的AppDelegate.swift
function 工作:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.