How to make NSToolbar label move with it's Icon when both of them are visible

时光怂恿深爱的人放手 提交于 2019-12-11 21:21:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!