Created
February 6, 2020 14:45
-
-
Save oleghnidets/19759eb5257be6e231114a4b8f060fe6 to your computer and use it in GitHub Desktop.
Tint image before iOS 13
This file contains 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
func tinted(withColor color: UIColor) -> UIImage { | |
guard let maskImage = cgImage else { | |
return self | |
} | |
let bounds = CGRect(origin: .zero, size: size) | |
let renderer = UIGraphicsImageRenderer(size: size) | |
return renderer.image { context in | |
let cgContext = context.cgContext | |
cgContext.clip(to: bounds, mask: maskImage) | |
color.setFill() | |
cgContext.fill(bounds) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment