我在右键点击时创建了NSStatusBarItem
和popUp a(以编程方式生成)NSMenu
:
let statusBarItem = NSStatusBar.system().statusItem(withLength: -1)
statusBarItem.action = #selector(AppDelegate.statusBarItemAction(sender:))
let menu = NSMenu()
var menuItem = NSMenuItem()
menuItem.action = #selector(AppDelegate.customItemAction)
menu.addItem(menuItem)
func statusBarItemAction(sender: NSStatusItem) {
let mouseEvent = NSEvent.pressedMouseButtons()
if mouseEvent == 2 {
// right click
lxStatusBarItem.popUpMenu(menu)
}
}
func customItemAction() {
// do something
}
一切正常,但statusBarItem
在调用customItemAction
后仍然突出显示:
我该如何解决这个问题?
答案 0 :(得分:0)
我发现设置statusItem.button?.isHighlighted = false
有助于删除突出显示。在您的情况下,这将是这样的:
func customItemAction() {
// do something
statusBarItem.button?.isHighlighted = false
...
}