RenderUIViewToUIImage
A demo showing how to render a UIView to UIImage and save to the user's camera roll.
func createImage() {
let renderer = UIGraphicsImageRenderer(size: view.bounds.size)
let image = renderer.image { context in
view.drawHierarchy(in: view.bounds, afterScreenUpdates: true)
}
// save image to camera roll
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
}
If working on your own app and saving to the user's camera roll it's a requirement to add the
NSPhotoLibraryAddUsageDescription
key to theInfo.plist
and a String explaning the reason for saving to the camera roll.