Using Tint color on UIImageView
You can also just set this on your asset. Make sure your image contains all white pixels + transparent.
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)
Swift version: 5.2
let tintableImage = UIImage(named: "myImage")?.withRenderingMode(.alwaysTemplate)
imageView.image = tintableImage
imageView.tintColor = UIColor.red
Objective C
self.imgView.image = [self.imgView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[self.imgView setTintColor:[UIColor darkGrayColor]];
Or
You can also just set this on your asset.
(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