0

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!

  • Maybe a duplicate or similar to: http://stackoverflow.com/questions/30005185/nsview-added-to-nsstatusitem-button-has-an-opaque-border – Erik Oct 29 '15 at 20:41

1 Answers1

1

I guess you could set the button type to MomentaryChangeButton, a type of button that does not get highlighted when clicked.

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.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253