FROM : Christiaan Hofman
DATE : Tue Feb 01 13:47:37 2005
Hi,
You should use an image for that. However, NSPopUpButton does not do a
good job drawing the image, as it wants all kinds of extra spacing, and
you also have to get rid of the extra arrow, which can only be done
programatically.
I myself use a custom NSPopUpButton/NSPopUpButtonCell subclass pair.
This has the advantage that the superclass can manage the menu.
Basically, it uses an embedded NSButtonCell to do the drawing related
stuff (mainly -drawWithFrame:inView:). To make it easier to work with,
I redirect several setters to the embedded buttoncell (like setImage,
setAlternateImage, setEnabled, ...). The most important methods to
subclass:
-initTextCell:pullsDown:
designated initializer, so changes all initializers
use setBordered:NO and setImagePosition:NSImageOnly on the buttoncell
-dealloc
-drawWithFrame:inView:
echo to the buttoncell
-highlight:withFrame:inView:
highlight both super and buttoncell
-setImage:
echo to buttoncell
-performClick:
click both super and buttoncell
The popupbutton subclass should implement the +cellClass class method
to return your cell subclass.
Another tip, if you want to be able to connect it in IB, you should
implement the popupbutton subclass's initWithCoder: which should
replace the (wrong) cell with you subclass (copying relevant settings).
Yet another tip, the same subclass could be used for a cornerview popup.
HTH,
Christiaan
On Feb 1, 2005, at 14:01, Miguel Arroz wrote:
> Hi!
>
> How can I implement a pop-up menu like Apple does in their apps
> (Mail.app for example) that has a little gear icon and is used to list
> the possible actions to do with a selected item? I'm playing with
> Interface Builder but I cannot achieve the same effect.
>
> Yours
>
> Miguel Arroz
>
DATE : Tue Feb 01 13:47:37 2005
Hi,
You should use an image for that. However, NSPopUpButton does not do a
good job drawing the image, as it wants all kinds of extra spacing, and
you also have to get rid of the extra arrow, which can only be done
programatically.
I myself use a custom NSPopUpButton/NSPopUpButtonCell subclass pair.
This has the advantage that the superclass can manage the menu.
Basically, it uses an embedded NSButtonCell to do the drawing related
stuff (mainly -drawWithFrame:inView:). To make it easier to work with,
I redirect several setters to the embedded buttoncell (like setImage,
setAlternateImage, setEnabled, ...). The most important methods to
subclass:
-initTextCell:pullsDown:
designated initializer, so changes all initializers
use setBordered:NO and setImagePosition:NSImageOnly on the buttoncell
-dealloc
-drawWithFrame:inView:
echo to the buttoncell
-highlight:withFrame:inView:
highlight both super and buttoncell
-setImage:
echo to buttoncell
-performClick:
click both super and buttoncell
The popupbutton subclass should implement the +cellClass class method
to return your cell subclass.
Another tip, if you want to be able to connect it in IB, you should
implement the popupbutton subclass's initWithCoder: which should
replace the (wrong) cell with you subclass (copying relevant settings).
Yet another tip, the same subclass could be used for a cornerview popup.
HTH,
Christiaan
On Feb 1, 2005, at 14:01, Miguel Arroz wrote:
> Hi!
>
> How can I implement a pop-up menu like Apple does in their apps
> (Mail.app for example) that has a little gear icon and is used to list
> the possible actions to do with a selected item? I'm playing with
> Interface Builder but I cannot achieve the same effect.
>
> Yours
>
> Miguel Arroz
>
| Related mails | Author | Date |
|---|---|---|
| Miguel Arroz | Feb 1, 13:01 | |
| Kiran B | Feb 1, 13:11 | |
| Stephane Sudre | Feb 1, 13:38 | |
| Christiaan Hofman | Feb 1, 13:47 |






Cocoa mail archive

