views:

367

answers:

3
+3  A: 

See Selectable Toolbar Items in the Cocoa documentation.

Chuck
+7  A: 

To expand upon Chuck's answer, you simply need to make your controller the delegate of your NSToolBar and implement the toolbarSelectableItemIdentifiers: delegate method in it. For example, the following implementation will let you retain the selection highlight on every toolbar item except for the one labeled "Inspect":

- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
{
    NSMutableArray *allIdentifiers = [[NSMutableArray alloc] init];

    for (NSToolbarItem *toolbarItem in [toolbar items])
    {
     if (![[toolbarItem label] isEqualToString:@"Inspect"])
      [allIdentifiers addObject:[toolbarItem itemIdentifier]];
    }

    return [allIdentifiers autorelease];
}

I cache the allIdentifiers array in an instance variable when I do something like this, so that I only have to do the array construction once.

Brad Larson
A: 

If you made your toolbar in Interface Builder, you can click on the individual NSToolbarItems and check the Selectable box in the Inspector for the ones you want to have that look. No code needed.

sam