Skip to content

Instantly share code, notes, and snippets.

@Anatoli-Petrosyants
Created April 19, 2018 07:07
Show Gist options
  • Select an option

  • Save Anatoli-Petrosyants/2264abf8085c4f6c5f9af48a7169d43f to your computer and use it in GitHub Desktop.

Select an option

Save Anatoli-Petrosyants/2264abf8085c4f6c5f9af48a7169d43f to your computer and use it in GitHub Desktop.
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