Skip to content

Instantly share code, notes, and snippets.

@naturaln0va
Created July 7, 2015 20:34
Show Gist options
  • Save naturaln0va/c47d246e0e5d608be803 to your computer and use it in GitHub Desktop.
Save naturaln0va/c47d246e0e5d608be803 to your computer and use it in GitHub Desktop.
Get a UIImage of the contents of a UIView
extension UIView
{
func imageByCapturing() -> UIImage
{
UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, 0.0)
self.drawViewHierarchyInRect(self.frame, afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment