Skip to content

Instantly share code, notes, and snippets.

@oleghnidets
Created February 6, 2020 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oleghnidets/19759eb5257be6e231114a4b8f060fe6 to your computer and use it in GitHub Desktop.
Save oleghnidets/19759eb5257be6e231114a4b8f060fe6 to your computer and use it in GitHub Desktop.
Tint image before iOS 13
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