NSToolbarItemGroup without spaces

I use NSToolbarItemGroup to group a set of NSToolbarItem items. Currently there are 2pt spaces between each element in the group, ideally I would like them to be completely merged visually similar to NSSegmentedControl.

After checking the Mail application, it looks like they are using a custom NSToolbarItem containing NSSegmentedControl. I have tried this in the past, but I cannot figure out how to get individual labels under each component and each component is displayed individually in the overflow menu.

Current view:

enter image description here

Desired view:

enter image description here

I know that β€œCentered” is cropped, it's just a quick implementation.

+5
source share
2 answers

I can suggest you use the NSSegmentControl added to NSToolbarItem , as in the picture below.

enter image description hereimage

You need shortcuts under the buttons (for example, "Reply", etc.). To do this, you can set the NSToolbarItem label-property and play with a space between words.

attributes inspector

+1
source

You can add the NSToolbarItem object to the toolbar, and then set the NSViewController as follows (using Swift):

 runStatus.view = RunStatusView() 

where "runStatus" is the name of @IBOutlet for NSToolbarItem, and "RunStatusView" is an NSView object with an override of the drawRect method. You can also specify the width and height of the NSView; for example, make the width constant at 125:

 runStatus.minSize = NSSize(width: 125, height: 32) runStatus.maxSize = NSSize(width: 125, height: 32) 

This can cause NSToolbar elements to be closer to each other, depending on what you draw on them.

Finally, if you still cannot get exactly what you want, make the button group one NSToobarItem, and in "RunStatusView" (using the example above) draw it as you want and redefine the mouseDown event (also in "RunStatusView") to see exactly where the user clicks. Then there is one NSToolbarItem element that essentially acts like a few buttons, and you have full control and can make it behave as you like.

+1
source

All Articles