In Swift 3, when I try to programmatically change the color of an image loaded from assets just like this:
let imageView = UIImageView()
let image = UIImage(named: "imageFromAssets")?.withRenderingMode(.alwaysTemplate)
imageView.contentMode = .scaleAspectFit
imageView.tintColor = GREEN_UICOLOR // Change to custom green color
imageView.image = image
The image shows up as a square block below:
However, the funny thing is this does not always happen. With some other images in the assets, it works and changes the tint to green:
Why is there inconsistent behavior here? And in general how do I add a template image to assets, and be able to programmatically change its color? I realize when I do not change the image to a template image it works, but I can't do that because I want to change the image's tint.
For template images the background needs to be transparent - not white.