Skip to content

Instantly share code, notes, and snippets.

@nanoxd
Last active September 22, 2018 16:45
Show Gist options
  • Save nanoxd/0a78064e65b72895dec1cc2901658899 to your computer and use it in GitHub Desktop.
Save nanoxd/0a78064e65b72895dec1cc2901658899 to your computer and use it in GitHub Desktop.
[ScreenShottable] Screenshot a view using UIGraphicsImageRenderer #swift #uikit
protocol Screenshottable {
func screenshot() -> UIImage?
}
extension UIView: Screenshottable {
func screenshot() -> UIImage? {
let renderer = UIGraphicsImageRenderer(bounds: bounds)
return renderer.image { _ in
drawHierarchy(in: self.bounds, afterScreenUpdates: false)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment