Skip to content

Instantly share code, notes, and snippets.

@soggybag
Created November 19, 2015 23:11
Show Gist options
  • Save soggybag/c1e341de555d98a9e92f to your computer and use it in GitHub Desktop.
Save soggybag/c1e341de555d98a9e92f to your computer and use it in GitHub Desktop.
Screenshot UIView Extension, adds a simple method to return a image from a UIView
// UNTESTED!
extension UIView {
func takeScreenshot() -> UIImage {
UIGraphicsBeginImageContextWithOptions(self.bounds.size, true, 0.0)
self.drawViewHierarchyInRect(self.bounds, 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