FROM : Ron Fleckner
DATE : Sun Jan 27 05:36:44 2008
On 27/01/2008, at 9:09 AM, Pierre Bernard wrote:
> Hi!
>
> I would like to create a custom menu item much like the search item
> used in Leopard's Help or Spotlight menus.
>
> I thought this ought to be simple under Leopard, as it is now
> possible to add an arbitrary view to a menu item. This however only
> gets me 80% of the way and I am not even sure a working solution
> lies in that direction. The problem is that the custom view does
> not cover all of the menu item. There remains a border above and
> below of my view.
>
> - Is there a way to stretch my view over those borders?
> - Where does the menu do its drawing? NSMenuItem is neither a view
> nor a cell. I believe the custom view takes NSMenuItemCell out of
> the loop.
> - What was the pre-Leopard way of doing this? I remember something
> about going down to Carbon, but can't find much information on the
> web.
>
> Best,
> Pierre
Hi Pierre,
I don't know about Leopard (yet), but on Tiger you can add any
arbitrary image to a menu item. In the code below, "colours" is a
rainbow-like image 22 px by 100 px. The variable "title" is an empty
string. This works on Tiger with no border around the image. I
haven't experimented with larger images, but they might work on Leopard.
NSImage *myImage = [NSImage imageNamed:@"colours"];
// Make the menu
NSMenuItem *newItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]]
initWithTitle:title action:NULL keyEquivalent:@""];
[newItem setImage: myImage];
Is that what you're after?
HTH,
Ron
DATE : Sun Jan 27 05:36:44 2008
On 27/01/2008, at 9:09 AM, Pierre Bernard wrote:
> Hi!
>
> I would like to create a custom menu item much like the search item
> used in Leopard's Help or Spotlight menus.
>
> I thought this ought to be simple under Leopard, as it is now
> possible to add an arbitrary view to a menu item. This however only
> gets me 80% of the way and I am not even sure a working solution
> lies in that direction. The problem is that the custom view does
> not cover all of the menu item. There remains a border above and
> below of my view.
>
> - Is there a way to stretch my view over those borders?
> - Where does the menu do its drawing? NSMenuItem is neither a view
> nor a cell. I believe the custom view takes NSMenuItemCell out of
> the loop.
> - What was the pre-Leopard way of doing this? I remember something
> about going down to Carbon, but can't find much information on the
> web.
>
> Best,
> Pierre
Hi Pierre,
I don't know about Leopard (yet), but on Tiger you can add any
arbitrary image to a menu item. In the code below, "colours" is a
rainbow-like image 22 px by 100 px. The variable "title" is an empty
string. This works on Tiger with no border around the image. I
haven't experimented with larger images, but they might work on Leopard.
NSImage *myImage = [NSImage imageNamed:@"colours"];
// Make the menu
NSMenuItem *newItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]]
initWithTitle:title action:NULL keyEquivalent:@""];
[newItem setImage: myImage];
Is that what you're after?
HTH,
Ron
| Related mails | Author | Date |
|---|---|---|
| Pierre Bernard | Jan 26, 23:09 | |
| Jonathon Mah | Jan 27, 02:45 | |
| Ron Fleckner | Jan 27, 05:36 | |
| Pierre Bernard | Jan 27, 05:45 | |
| Pierre Bernard | Jan 27, 05:46 | |
| Eric Schlegel | Jan 27, 06:59 |






Cocoa mail archive

