Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@florian-muc
Last active May 1, 2023 07:52
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save florian-muc/7460cbb3c3cdc1a03cf879442f545cd9 to your computer and use it in GitHub Desktop.
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()"
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
}
}
@florian-muc
Copy link
Author

For use with the new debugger integration in Kaleidoscope 2.4 and later: https://kaleidoscope.app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment