Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func withColor(_ color: UIColor) -> UIImage {
- UIGraphicsBeginImageContextWithOptions(size, false, scale)
- guard let ctx = UIGraphicsGetCurrentContext(), let cgImage = cgImage else { return self }
- color.setFill()
- ctx.translateBy(x: 0, y: size.height)
- ctx.scaleBy(x: 1.0, y: -1.0)
- ctx.clip(to: CGRect(x: 0, y: 0, width: size.width, height: size.height), mask: cgImage)
- ctx.fill(CGRect(x: 0, y: 0, width: size.width, height: size.height))
- guard let colored = UIGraphicsGetImageFromCurrentImageContext() else { return self }
- UIGraphicsEndImageContext()
- return colored
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement