I have a UIImage
that is a small symbol that is all black. The UIImage
is getting set in a custom UIButton
subclass I have. Is it possible to have the image to apply the tintColor
to it, so instead of the black image it changes colors to whatever the tintColor
is?
I'm just trying to avoid creating new assets.
// here I want defaultImageName (that is black) to use the tintColor (that is white) [self setImage:[UIImage imageNamed:defaultImageName] forState:UIControlStateNormal];
setBlendMode(. multiply) ctx. draw(image. cgImage!, in: imageRect) let newImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return newImage! } }
UIImage *img = [[UIImage alloc] init]; [img setImage:[UIImage imageNamed:@"anyImageName"]];
If you are just supporting iOS 7 you can use tintColor
and UIImageRenderingModeAlwaysTemplate
This article covers that:
https://www.captechconsulting.com/blogs/ios-7-tutorial-series-tint-color-and-easy-app-theming
If you need to support an earlier version you may want to consider this thread
How would I tint an image programmatically on the iPhone?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With