I have a TableView
who presents a PickerViewController
on a ViewController
. The ViewController show some Images and a button than triggering an action. I want that this action takes a screenshot as the screenshot that is provided by Apple.
Here is my code:
@IBAction func share(){
UIGraphicsBeginImageContext(view.frame.size)
UIGraphicsBeginImageContext(thePicker.view.frame.size)
view.layer.render(in: UIGraphicsGetCurrentContext()!)
thePicker.view.layer.render(in: UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
let activity = UIActivityViewController(activityItems: [image], applicationActivities: nil)
present(activity, animated: true, completion: nil)
}
This image is the result of using the screenshot provided by Apple (side + home button)This image is result of my code
you should write a extension for view's screenshot.Extension's return value is UIImage.You can print UIImage to UIImageview. Also if you want to, you can call here a button action.
Enjoy it :)