How to make NSSearchField take up whole width of toolbar

345 views Asked by At

I am trying to make a NSSearchField taking up the whole width of a toolbar in a NSWindowController.

  1. I created a new NSWindowController using Xcode storyboard, add a toolbar to it, when add search field to the toolbar.
  2. I drag the search field from allowed toolbar items to default toolbar items
  3. Set toolbar item's max width to a large number say 1000

I build the app and run. The search field shrinks when window width shrinks, but does not expand beyond a certain width when window width expands.

The question is how to make search field expand and take up all remaining space of the toolbar? enter image description here

1

There are 1 answers

2
Charles Srstka On

It doesn't sound to me like the toolbar is really what you want to use here. The purpose of the toolbar is to allow multiple UI elements to be included in a user-configurable way. If you want to force one element that takes up the entire width, I suggest just putting it in the window's content view and setting up the layout constraints to pin to both the left and right sides. If you set the "Textured" check box in Interface Builder, it should look roughly the same as it would have looked using the toolbar.