Created
April 10, 2018 04:54
-
-
Save brownsoo/24557db9277eace58b5a2aec25be975f to your computer and use it in GitHub Desktop.
tint color UIImage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public extension UIImage { | |
func tint(_ color: UIColor) -> UIImage { | |
let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height) | |
let renderer = UIGraphicsImageRenderer(size: rect.size) | |
let result = renderer.image { c in | |
color.setFill() | |
c.fill(rect) | |
self.draw(in: rect, blendMode: .destinationIn, alpha: 1) | |
} | |
return result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment