1

I searched SO and tried many given solutions but in vain, am developing an app in which i need to take a screenshot, i have a UIViewController and a scrollview, In the scrollview i have some labels and at the bottom of the screen i have a button, which is visible when i scroll to the bottom.

When i click the button which is at the bottom of the screen, i want to capture all of the screen from top to bottom, but the problem i am facing is, its not scrolling to the top, i am getting only the visible area of the screen in the screenshot, as seen in this image: I am using below code, Thanks in advance

//Create the UIImage
UIGraphicsBeginImageContext(view.bounds.size)  //view.frame.size
view.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
sharedImage = image
Abdul Rafay
  • 266
  • 1
  • 2
  • 15

1 Answers1

2

What you are doing is taking the screenshot of SuperView which is on top of UIViewController. You need to take screenshot of UIScrollView and for that you need to pass the contentSize of UIScrollView.

//Create the UIImage

UIGraphicsBeginImageContext(scrollView.contentSize)  //Change this line only
view.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
sharedImage = image

Now you will get the screenshot of complete UIScrollView.

Sohil R. Memon
  • 9,404
  • 1
  • 31
  • 57