Created
April 19, 2018 07:07
-
-
Save Anatoli-Petrosyants/2264abf8085c4f6c5f9af48a7169d43f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 snapshot: UIImage? { | |
| UIGraphicsBeginImageContext(self.frame.size) | |
| guard let context = UIGraphicsGetCurrentContext() else { | |
| return nil | |
| } | |
| layer.render(in: context) | |
| let image = UIGraphicsGetImageFromCurrentImageContext() | |
| UIGraphicsEndImageContext() | |
| return image | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment