0

I'm doing Swift and iOS and I have a question.

Lets say I am in ViewController1 and I want an image of TableViewController1 after that class calls viewDidLoad(), is this possible?

I know its possible to convert the current view into a UIImage etc, but is it possible to do it of another view?

Any help is appreciated. Thanks!

Edit: Here is the plan. I call func x() in ViewController1 . What this method should essentially do is return a UIImage of TableViewController1 instance after viewDidLoad() was called in TableViewController1. Is this clear?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Aakarsh
  • 63
  • 7

2 Answers2

1

There is an extension to UIView which you can use in viewDidAppear() for example to make screenshot of screen

extension UIView{

 var screenshot: UIImage{

    UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.main.scale)
    let context = UIGraphicsGetCurrentContext();
    self.layer.render(in: context!)
    let screenShot = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return screenShot!
 }
}
nerowolfe
  • 4,787
  • 3
  • 20
  • 19
0

You can take a "screenshot" so to speak of whatever is drawn on the screen. So, if your view controller is currently on the screen, you can capture it from any event/handler.

Use UIGraphicsBeginImageContext to define the area. Look in the documentation for further steps.

Or

See this answer for an actual method that can help you.

neeks
  • 316
  • 2
  • 8