/RenderUIViewToUIImage

A demo showing how to render a UIView to UIImage and save to the user's camera roll.

Primary LanguageSwift

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)
}

Screen Shot 2021-07-28 at 6 47 02 PM

If working on your own app and saving to the user's camera roll it's a requirement to add the NSPhotoLibraryAddUsageDescription key to the Info.plist and a String explaning the reason for saving to the camera roll.