I've found this code:
func screenShotMethod() {
//Create the UIImage
UIGraphicsBeginImageContext(view.frame.size)
view.layer.renderInContext(UIGraphicsGetCurrentContext())
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
//Save it to the camera roll
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
}
What do I need to do to get all the other elements, like the navigation bar, into the screenshots?
Swift 3 Extension for UIWindow
The recommended way to create a context in iOS 10 is to use
UIGraphicsImageRenderer
.This is similar, hopefully it helps someone in the future.
Here's a Swift 3 solution
https://gist.github.com/nitrag/b3117a4b6b8e89fdbc12b98029cf98f8
For ease I would add an extension in it's own file
call the extension as follows...
Similarly, one could extended UIView to capture an image of that....
Details
Xcode 9.3, Swift 4.1
Tested on iOS: 9, 10, 11
Solution
Usage
Details
Xcode 8.2.1, swift 3
Version 1 for iOS 10x
Version 2 for iOS 9x, 10x
Usage