setBlendMode(. multiply) ctx. draw(image. cgImage!, in: imageRect) let newImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return newImage! } }
Tint is the default colour for textfields, labels etc. The Tint doesn't effect anything, it just changes the colour of certain properties (e.g. textfields, and labels etc. to blue / red / green etc.)
tintColor is a variable in UIView that returns a color. The color returned is the first non-default value in the receiver's superview chain (starting with itself). If no non-default value is found, a system-defined color is returned (the shiny blue you always see).
Instead of this code:
[image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
you should have:
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
Use this in Swift 4.1
image = UIImage(named: "name")!.withRenderingMode(.alwaysTemplate)
You can also just set this on your asset. Make sure your image contains all white pixels + transparent.
(Can't edit @Zhaolong Zhong post)
In swift 3.0, you can do:
let image = UIImage(named: "your_image_name")!.withRenderingMode(.alwaysTemplate)
yourImageView.image = image
yourImageView.tintColor = UIColor.blue
In swift 2.0+, you can do:
let image = UIImage(named: "your_image_name")!.imageWithRenderingMode(.AlwaysTemplate)
yourImageView.image = image
yourImageView.tintColor = UIColor.blueColor()
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