What do you mean by "template"?
In macOS, a template NSImage is one whose colors are ignored, and the only significant information is the opacity (transparency) of the pixels. When you specify a template image for a button, the button colorizes the image with a standard color suitable for the button state (normal, highlighted, etc). You can't control which color is used.
If you want that behavior, then you must specify that the image is a template, and there are two ways to do this:
1. Load the NSImage and set its isTemplate property to true.
2. Load the NSImage using NSImage(named:), and specify an image file name that ends in the word "Template" (e.g. "MyImage Template.pdf", which you load as NSImage(named:"MyImage Template")).
Note that if you're setting the image name for a button in IB, you can use technique #2 to get it to be a template.