Re: Displaying a menu at arbitrary location.
Re: Displaying a menu at arbitrary location.
- Subject: Re: Displaying a menu at arbitrary location.
- From: Gideon King <email@hidden>
- Date: Mon, 13 May 2002 23:16:24 +0800
Thanks for the suggestion - I was able to use a variation on this theme
to get something that approximates what is described in the HI
guidelines (implementing the option where the icon changes to reflect
the selection).
In case someone else needs to do the same thing, the following are the
steps:
1. Put the pop up button on the interface, choosing "Pull down" and
"Shadowless Square" style.
2. Make the button at least 12 pixels wider than the images you are
going to display on it (otherwise your image will be cropped).
3. In your code (awakeFromNib or some other suitable place), build the
menu item list, with images and text. The item at position 0 will hold
the current selected image, so will be replaced all the time. The rest
of the items are the actual items you want in your menu.
4. Set the state of the initially selected item to 1, and set the image
for item 0 as the icon for the selected item.
5. On the popup button, call setBordered:NO and
setImagePosition:NSImageOnly
6. The popup button should have a target and action associated with it
to call a method, which will look something like:
- (IBAction)select:sender
{
NSMenuItem *item = [sender selectedItem];
NSMenuItem *baseItem = [sender selectedItem];
NSArray *itemArray = [myPopup itemArray];
int i;
// Manage the selection tick
for (i = 0; i < [itemArray count]; i++)
{
NSMenuItem *thisItem = [itemArray objectAtIndex:i];
[thisItem setState:0];
}
[item setState:1];
baseItem = [myPopup itemAtIndex:0];
// In our case, we don't want a title on the button...
[baseItem setTitle:@""];
[baseItem setImage:[[sender selectedItem] image]];
// But we do want to update the tool tip...
[myPopup setToolTip:[item title]];
// Now process the menu selection in whatever way you want.
}
And that's about it. Of course if you want a "Pop-up bevel button", then
you don't want to do the setBordered:NO
Hope this is useful to someone, sometime...
Gideon.
On Monday, May 13, 2002, at 07:09 AM, bill fancher wrote:
Create an NSPopupButton in IB. In the info window Attributes pane
choose "Pull Down". Choose "Square" or "Shadowless Square" style.
Delete the default title and enter your icon name. Go to the Size pane
to adjust size accordance with HIG.
I believe that's what you're looking for. I never tried it in a real
app. Please let me know if you run into problems.
HTH,
--
bill
On Sunday, May 12, 2002, at 05:59 AM, Gideon King wrote:
I am implementing a pop-up icon button as described in the HI
guidelines document. In order to do this, I need to be able to display
a menu just below the button that is clicked, aligned with the left
side of the button. As NSMenu doesn't have any relationship with
NSView, I'm not sure how to display the menu where I want it.
NSPopupButton doesn't help as the menus don't display in the right
place and also won't display large images. Context menus don't seem to
help as there seems no way to control where they display.
Any pointers on how to display a menu where I want it would be
appreciated.
Thanks
Gideon King
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.