Skip to content

Instantly share code, notes, and snippets.

@dsowsy
Created October 28, 2015 17:24
Show Gist options
  • Select an option

  • Save dsowsy/e22f9cb4b6e226b0d714 to your computer and use it in GitHub Desktop.

Select an option

Save dsowsy/e22f9cb4b6e226b0d714 to your computer and use it in GitHub Desktop.
Snapshot any UIView
extension UIView {
func snapshot() -> UIImage {
UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.mainScreen().scale)
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