Question

I'm trying to create a mask from an image with a transparent background. I want to create a new UIImage where any pixel that has > 0 alpha to turn gray.

Was it helpful?

Solution

You can load an image with rendering mode UIImageRenderingModeAlwaysTemplate which draws the image as a template image, ignoring its color information.

[[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

Then set the tintColor of the container to gray

yourImageView.tintColor = [UIColor grayColor];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top