Can I center a NSToolbarItem in a toolbar?

Viewed 4805

Its just that. I want to center two buttons. My toolbar looks like this ([B] is a button) :

[B] <---- flexible space ---> [B][B] <---- flexible space ---> [SearchBar]

But the search bar is bigger than the button on the far left so the middle buttons are not centered. I tried adding a view with a custom width but that is screwed up by localization. Is there a way to center them?

4 Answers

If your deployment target is macOS 10.14 (Mojave) or later, you can center a toolbar item by setting the toolbar's centeredItemIdentifier property to the identifier of the item you want centered.

This is intended for centering the toolbar item that contains the window title when you have set the window's titleVisibility to NSWindowTitleHidden. It might not work as well in other scenarios.

Related