Search code examples
macospdfnsimagetint

How to tint a vectorial NSImage (PDF)


All my images are monochrome PDF in XCAssets. I would like to color them at runtime but I can't find any tint property in NSImage.

When I use NSRectFillUsingOperation it rasterises the picture, so I'd rather avoid it.

In summary how can I tint vectorial NSImages using RGB without rasterising ?


Solution

  • I ended up setting a CIFilter called "CIFalseColor" over the button in the IB and then at runtime I control the color with :

    button.contentFilters[0].setValue(myCIColor, forKey: "inputColor1")
    

    This works if your image is white, inputColor2 controls the black, so I presume that a greyscale image would be a mix between the two.

    It's not the best because it hurts the performance of the app but it will do until somebody finds a better way.