Is there an easy way to tint a template NSImage?

Recently, I've been working with NSVisualEffectView (for the first time) and that introduced me to template images.


As I understand it, using a template image in a visual effect view will allow the image to be vibrant. This made me wonder if I could also work with template images in non-vibrant views and tint them where necessary.


For example, rather than specify separate images for the highlighted and disabled states of my control, I could just change the tint color instead.

Less work for my designer too!


Or am I misunderstanding what template images are for?

Replies

I think you do understand what template images are for, but I beleive you also misunderstand what NSVisualEffectsView are for. Some NSControl subclass and NSView have a tintColor property accessible in code and in IB. If you don't see that property in IB or in the docs for the type of control or view that you use than I'm afraid your out of luck. NSVisualEffectsView does provide vibrancy ( a blend mode with some blur that Apple does not provide the exact details of) but the color or tint used to draw the template image is not specific to NSVisualEffectsViews a user can diable vibrancy in System Preferences-> Accessibility->Screen and template images still work as they should but sidebars, toolbars and window backgrounds loose their vibrancy effect. In fact, you only need to provide your images in solid colors either as png in 1x and 2x or in pdf only 1x resolution is needed in that case and you mark them as template images in your asset catalog and you can use them in any control or view that supports images, that is assuming your using a standard AppKit control or view. If you want to subclass something like NSButtonCell on the other hand an override the drawInterior method, than it might be easier to provide two version of your images rather than figuring out how to display them in different colors depending on their state.