Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I center a NSToolbarItem in a toolbar?

Tags:

macos

cocoa

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?

like image 523
david Avatar asked Jul 22 '11 11:07

david


2 Answers

A very belated response but since I also needed to do this i've just written a subclass that will create a space to center the next toolbar item:

http://github.com/timothyarmes/TAAdaptiveSpaceItem

like image 134
tarmes Avatar answered Nov 11 '22 21:11

tarmes


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.

like image 33
rob mayoff Avatar answered Nov 11 '22 23:11

rob mayoff