问题
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