Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. func withColor(_ color: UIColor) -> UIImage {
  2.  
  3. UIGraphicsBeginImageContextWithOptions(size, false, scale)
  4. guard let ctx = UIGraphicsGetCurrentContext(), let cgImage = cgImage else { return self }
  5. color.setFill()
  6. ctx.translateBy(x: 0, y: size.height)
  7. ctx.scaleBy(x: 1.0, y: -1.0)
  8. ctx.clip(to: CGRect(x: 0, y: 0, width: size.width, height: size.height), mask: cgImage)
  9. ctx.fill(CGRect(x: 0, y: 0, width: size.width, height: size.height))
  10. guard let colored = UIGraphicsGetImageFromCurrentImageContext() else { return self }
  11. UIGraphicsEndImageContext()
  12. return colored
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement