Created
February 16, 2018 10:08
-
-
Save StanDimitroff/9c1dc069000d9f10b057e74861a3f6bc to your computer and use it in GitHub Desktop.
UIImage from UIView
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 UIView { | |
var asImage: UIImage? { | |
UIGraphicsBeginImageContextWithOptions( | |
CGSize(width: self.frame.width, height: self.frame.height), true, 1) | |
self.layer.render(in: UIGraphicsGetCurrentContext()!) | |
guard let image = UIGraphicsGetImageFromCurrentImageContext() else { return nil } | |
UIGraphicsEndImageContext() | |
return image | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment