Last active
September 22, 2018 16:45
-
-
Save nanoxd/0a78064e65b72895dec1cc2901658899 to your computer and use it in GitHub Desktop.
[ScreenShottable] Screenshot a view using UIGraphicsImageRenderer #swift #uikit
This file contains 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
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