Created
November 19, 2015 23:11
-
-
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
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
// 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