问题
My app has an NSToolbar
with a horizontal NSSplitView
below it. An NSSegmentedControl
in the toolbar moves with the splitview's divider, just like the one in OS X's Finder. NSLayoutGuide was used to align the two "views" from different storyboard "scenes". I shared this approach in this related question.
However, I don't know how to move the label with the icon. I've set the minSize
and maxSize
, but the label is fixed. In the first screenshot below, the "View Mode" label is not right below the segmented control.
It will be easy to add constrains to the label if I can access it. But I haven't found the API in NSToolbarItem, which only has a public view
property. I've examine the view's hierarchy (the second screenshot), but I don't think I should use the variables with the _
prefix.
A related but different question is here. That question doesn't take moving into account.
回答1:
You could try subclassing the NSToolbar setting the title to @"" and then creating your own UILabel and adding it as a subview? then you could reference it's property name and move it wherever you like
来源:https://stackoverflow.com/questions/32564021/how-to-make-nstoolbar-label-move-with-its-icon-when-both-of-them-are-visible