NSPopupButton on Toolbar with Image instead?

  • Hello,

    I'm trying to get the XCode style contextual menu to popup when a
    button is clicked on my toolbar (such as the "Build" button if you
    hold it), but I can't figure out exactly how to do this!

    Should I be subclassing NSPopupButton? NSButtonCell? Is there an
    easier way for me to do this?

    Thank you,
    Mitchell
  • On Jan 15, 2008, at 9:45 AM, Mitchell Hashimoto wrote:

    > Hello,
    >
    > I'm trying to get the XCode style contextual menu to popup when a
    > button is clicked on my toolbar (such as the "Build" button if you
    > hold it), but I can't figure out exactly how to do this!
    >
    > Should I be subclassing NSPopupButton? NSButtonCell? Is there an
    > easier way for me to do this?

    Hi Mitchell,

    I'd say the easiest way to do this is with a single segment,
    momentary style NSSegmentedControl.  You can assign both a menu and
    an action to the control to get this behavior.  Because segmented
    controls always draw their bezels, you should override drawRect: if
    you want it to look like Xcode's buttons.

    I hope that helps,
    -Peter
  • Hi Peter,

    I looked this up and the SegmentedControl looks perfect if I could get
    rid of the bezel. I'm not sure exactly how to do this by ovverriding
    drawRect... could you please expand upon this a little bit more? Thank
    you!

    On Jan 15, 2008 11:30 AM, Peter Ammon <pammon...> wrote:
    >
    > On Jan 15, 2008, at 9:45 AM, Mitchell Hashimoto wrote:
    >
    >> Hello,
    >>
    >> I'm trying to get the XCode style contextual menu to popup when a
    >> button is clicked on my toolbar (such as the "Build" button if you
    >> hold it), but I can't figure out exactly how to do this!
    >>
    >> Should I be subclassing NSPopupButton? NSButtonCell? Is there an
    >> easier way for me to do this?
    >
    > Hi Mitchell,
    >
    > I'd say the easiest way to do this is with a single segment,
    > momentary style NSSegmentedControl.  You can assign both a menu and
    > an action to the control to get this behavior.  Because segmented
    > controls always draw their bezels, you should override drawRect: if
    > you want it to look like Xcode's buttons.
    >
    > I hope that helps,
    > -Peter
    >
    >
  • > I'm trying to get the XCode style contextual menu to popup when a
    > button is clicked on my toolbar (such as the "Build" button if you
    > hold it), but I can't figure out exactly how to do this!
    >
    > Should I be subclassing NSPopupButton? NSButtonCell? Is there an
    > easier way for me to do this?

    You can also use Matt Gemmell's ImagePopUpButton at: http://mattgemmell.com/source

    Cheers, Patrick
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today