Mac Developer Library


AppKit Framework Reference NSToolbarItemGroup Class Reference

Deployment Target:

On This Page


NSToolbarItemGroup is a subclass of NSToolbarItem which contains subitems. The views and labels of the subitems are used, but the parent's attributes take precedence.

To configure an instance of NSToolbarItemGroup, you first create the individual toolbar items that will be the subitems:

  1. NSToolbarItem *item1 = [[[NSToolbarItem alloc] initWithItemIdentifier:@"Item1"] autorelease];
  2. NSToolbarItem *item2 = [[[NSToolbarItem alloc] initWithItemIdentifier:@"Item2"] autorelease];
  3. [item1 setImage:[NSImage imageNamed:@"LeftArrow"]];
  4. [item2 setImage:[NSImage imageNamed:@"RightArrow"]];
  5. [item1 setLabel:@"Prev"];
  6. [item2 setLabel:@"Next"];

and then put them in a grouped item:

  1. NSToolbarItemGroup *group = [[[NSToolbarItemGroup alloc] initWithItemIdentifier:@"GroupItem"] autorelease];
  2. [group setSubitems:[NSArray arrayWithObjects:item1, item2, nil]];

In this configuration, you get two grouped items, and two labels. This differs from ordinary NSToolbarItem objects because they are attached—the user drags them together as a single item rather than separately.

If you set a label on the parent item:

  1. [group setLabel:@"Navigate"];

you get two grouped items with one shared label.

If instead you set a view on the parent item, you get two labels with one shared view:

  1. [group setView:someSegmentedControl];

  • The subitems for the receiver.



    var subitems: [NSToolbarItem]


    @property(copy) NSArray <__kindof NSToolbarItem *> *subitems


    By default, an NSToolbarItemGroup instance has an empty array of subitems.


    Available in OS X v10.5 and later.