I have create a menubar 'button' which runs a function when it is clicked. Below is my code for the menubar button.
我创建了一个菜单栏“按钮”,它在点击时运行一个功能。下面是我的菜单栏按钮的代码。
let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(-1)
func applicationDidFinishLaunching(aNotification: NSNotification) {
if let button = statusItem.button {
button.title = "This is in the menu bar."
button.action = Selector("myFunction")
}
}
The problem is, this is going to be made into an image, not text, so I need it not to be highlighted blue when the user clicks it, which is what happens at the moment.
问题是,这将被制作成一个图像,而不是文本,因此我需要在用户点击它时不要将其突出显示为蓝色,这就是目前发生的情况。
Is there anything I can do to stop it being highlighted when the user clicks it?
当用户点击它时,我能做些什么来阻止它突出显示?
Thanks!
谢谢!
1 个解决方案
#1
0
I guess you could set the button type to MomentaryChangeButton
, a type of button that does not get highlighted when clicked.
我猜你可以将按钮类型设置为MomentaryChangeButton,这是一种在点击时不会突出显示的按钮。
button.setButtonType(NSButtonType.MomentaryChangeButton)
Short syntax:
语法短:
button.setButtonType(.MomentaryChangeButton)
In case you also want to get rid of the focus ring:
如果你也想摆脱焦点圈:
button.focusRingType = NSFocusRingType.None
Short syntax:
语法短:
button.focusRingType = .None
Note: I wrote "I guess" because I didn't verify that it works in your specific case of status bar button.
注意:我写了“我猜”,因为我没有验证它是否适用于您的状态栏按钮的特定情况。
#1
0
I guess you could set the button type to MomentaryChangeButton
, a type of button that does not get highlighted when clicked.
我猜你可以将按钮类型设置为MomentaryChangeButton,这是一种在点击时不会突出显示的按钮。
button.setButtonType(NSButtonType.MomentaryChangeButton)
Short syntax:
语法短:
button.setButtonType(.MomentaryChangeButton)
In case you also want to get rid of the focus ring:
如果你也想摆脱焦点圈:
button.focusRingType = NSFocusRingType.None
Short syntax:
语法短:
button.focusRingType = .None
Note: I wrote "I guess" because I didn't verify that it works in your specific case of status bar button.
注意:我写了“我猜”,因为我没有验证它是否适用于您的状态栏按钮的特定情况。