0

I have a View in iOS app where multiple wkwebview are added as subviews to render html contents. It shows all the content but when I try to take screen shot, it shows blank as if content is never rendered in wkwebviews.

code I used to take screenshot:

 //view is parent view which contains wkwebviews as childviews
 func takeScreenShot(view: UIView) -> UIImage{
    UIGraphicsBeginImageContext(view.bounds.size)
    view.layer.renderInContext(UIGraphicsGetCurrentContext()!)
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return image

}

When I check the UI Hierarchy, the content of wkwebviews are actually out of bound of the parent view. Is there proper way to take screenshot?

Rikesh Subedi
  • 1,755
  • 22
  • 21

1 Answers1

0

Did you try this:

UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
UIImage* uiImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Taken from here

Community
  • 1
  • 1
atulkhatri
  • 10,896
  • 3
  • 53
  • 89