Make NSToolbar Icon for NSToolbar

☆樱花仙子☆ 提交于 2019-12-10 04:35:42

问题


I'd like to make an icon for my NSToolbar that has the same system stylings applied to it as the template icons in IB. How do you do this? I can't get the toolbar to apply system stylings like it says it will in the HIG.

Thanks!


回答1:


If you mean for a monochromatic icon, make sure you set it as a template image. That's what tells the system to render it with the inner gray or blue gradient.




回答2:


In Mac OS X v10.5 or later, images whose name ends in the word "Template" are automatically marked as template images. NSImage Class Reference

NSImage *image = [NSImage imageNamed:@"MyImageTemplate"];

This also works for Interface Builder. More information: http://www.proppe.org/blog/2007/12/01/nsimage-templates/




回答3:


The toolbar doesn't do that automatically. You have to create the graphics yourself. The Lion-style icons are usually mid-gray with a subtle inner shadow and a 1px whitish drop shadow. Here's an example done in Photoshop:

And here's all the layer styling done to it:



The specific numbers and colors may vary depending on the icon's shape and size.

On a side note, the HIG was saying that icons may change depending on the control. For example, when you disable a button, its icon will be displayed semi-transparently.



来源:https://stackoverflow.com/questions/7136373/make-nstoolbar-icon-for-nstoolbar

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