-
-
Save florian-muc/7460cbb3c3cdc1a03cf879442f545cd9 to your computer and use it in GitHub Desktop.
Send screenshots of a UIWindow to Kaleidoscope using this simple extension. Usage: "kspo UIApplication.shared.windows.first!.pngScreenshot()"
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
import UIKit | |
extension UIWindow { | |
func screenshot() -> UIImage { | |
UIGraphicsBeginImageContextWithOptions(self.bounds.size, false, 0) | |
let renderer = UIGraphicsImageRenderer(bounds: self.bounds, format: UIGraphicsImageRendererFormat()) | |
let image = renderer.image( actions: { (context) in | |
self.drawHierarchy(in: self.bounds, afterScreenUpdates: true) | |
}) | |
UIGraphicsEndImageContext() | |
return image | |
} | |
func pngScreenshot() -> NSData { | |
let screenImage = self.screenshot() | |
let data = screenImage.pngData() | |
return data! as NSData | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For use with the new debugger integration in Kaleidoscope 2.4 and later: https://kaleidoscope.app