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
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.