I ran into this too. It's annoying. My problem was that I needed to explicitly set the minSize
and maxSize
of each item and of the containing group. Maybe this will work:
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
{
NSToolbarItem* retVal = nil;
if ([@"GroupItem" isEqual: itemIdentifier])
{
NSToolbarItem *item1 = [[NSToolbarItem alloc] initWithItemIdentifier:@"Item1"];
NSToolbarItem *item2 = [[NSToolbarItem alloc] initWithItemIdentifier:@"Item2"];
NSToolbarItemGroup *group = [[NSToolbarItemGroup alloc] initWithItemIdentifier:@"GroupItem"];
[group setSubitems:[NSArray arrayWithObjects:item1, item2, nil]];
item1.image = [NSImage imageNamed:NSImageNameQuickLookTemplate];
item1.minSize = item1.image.size;
item1.maxSize = item1.image.size;
item1.label = @"Prev";
item2.image = [NSImage imageNamed:NSImageNameQuickLookTemplate];
item2.minSize = item2.image.size;
item2.maxSize = item2.image.size;
item2.label = @"Next";
group.label = @"Navigate";
NSSize minSize = NSZeroSize;
NSSize maxSize = NSZeroSize;
for (NSToolbarItem* item in group.subitems)
{
minSize.width += item.minSize.width;
minSize.height = MAX(minSize.height, item.minSize.height);
maxSize.width += item.maxSize.width;
maxSize.height = MAX(maxSize.height, item.maxSize.height);
}
group.minSize = minSize;
group.maxSize = maxSize;
retVal = group;
}
return retVal;
}
Seems silly to me that this is not default behavior, but that didn't stop me from wasting half an hour figuring it out. Also, watch out for ordering -- if you set the subitems min and max size before putting them into the group's subitems collection, the group will reset the sizes for you to 32x32. Grrr.