I'm using an NSToolbarItemGroup to group a set of NSToolbarItem's together. Currently there is a 2pt space between each item in the group, ideally I would like them to be completely merged visually similar to an NSSegmentedControl.
After inspecting the Mail application it looks like they are using a custom NSToolbarItem containing an NSSegmentedControl. I have tried this in the past but I cannot figure out how to get individual labels under each component and to have each component show up individually in the 'overflow' menu.
Current Look:
Desired Look:
I know 'Centered' is being clipped, this is just a quick implementation.
You can add an NSToolbarItem object to the toolbar, and then set the NSViewController like this (using Swift):
runStatus.view = RunStatusView()
where "runStatus" is the name of the @IBOutlet for the NSToolbarItem, and "RunStatusView" is an NSView object with an override on the drawRect method. You can also specify the width and height of the NSView; for example, force the width to be constant at 125:
runStatus.minSize = NSSize(width: 125, height: 32)
runStatus.maxSize = NSSize(width: 125, height: 32)
This can make the NSToolbar items appear closer to each other, depending on what you are drawing on them.
Finally, if you still cannot get exactly what you want, then make the group of buttons a single NSToobarItem, and in "RunStatusView" (using the above example) draw it however you want, and override the mouseDown event (also in "RunStatusView") to see where exactly the user is clicking. Then there's one NSToolbarItem that essentially acts like multiple buttons, and you have total control and can make it behave however you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With