Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show Menu on button press instead of right mouse click in os x

Tags:

macos

swift

cocoa

When I assign a Menu to a button, the menu will be shown when the user right click the button.

I want to open the menu when the user left click the button.

Something similar to this:

enter image description here


I got it working using this code, However the menu is shown at the top right corner of my screen. What am I doing wrong?

@IBOutlet var meeenu: NSMenu!
@IBAction func Options(sender: NSButtonCell) {
    meeenu.popUpMenuPositioningItem(meeenu.itemAtIndex(0), atLocation: NSEvent.mouseLocation(), inView: self.view)
}
like image 838
Faisal Avatar asked Sep 01 '25 01:09

Faisal


1 Answers

I got it working finally using this code:

@IBOutlet var meeenu: NSMenu!
@IBAction func Options(sender: NSButtonCell) {
    meeenu.popUpMenuPositioningItem(meeenu.itemAtIndex(0), atLocation: NSEvent.mouseLocation(), inView: nil)
}
like image 157
Faisal Avatar answered Sep 02 '25 20:09

Faisal