Last active
November 9, 2018 00:01
-
-
Save helbertgs/304289b40f5f699e6dfe542a5d333253 to your computer and use it in GitHub Desktop.
Crop a UIImage
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
extension UIImage { | |
func crop(rect: CGRect) -> UIImage? { | |
if let image = self.cgImage, let cropped: CGImage = image.cropping(to: rect) { | |
return UIImage(cgImage: cropped) | |
} | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment