Automatic Styling/Tinting of NSToolbarItem

情到浓时终转凉″ 提交于 2020-01-01 19:05:44

问题


Is there a way to tell OS X to automatically style/tint a NSToolbarItem?

I've added an "Image Toolbar Item" via IB/Xcode and set the icon to a black PDF as described in the documentation.

However, my result does not resemble that of, for instance, the App Store:

I'm looking for something akin to what the TabBar in iOS does by default.

I'm new to OS X development... So any guidance would be appriciated!


回答1:


Images need to be made template'd in order to get the correct styling (such as the engraved & blue styling).

This can be done in code with -[NSImage setTemplate:] or by having your image names end with "Template" (requiring no code changes).


To get the blue styling specifically, you have to set a borderless NSButton as the custom view of the toolbar item (rather than it being a standard item). That button has to have a type that results in it showing its state (e.g. a Round-Textured Toggle button), and when it has an On state, it will get then blue styling.



来源:https://stackoverflow.com/questions/24599559/automatic-styling-tinting-of-nstoolbaritem

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