Reputation: 23
I need convert the contents of an UICollectionView
into an UIIImage
. But, the image only contains the visible portion of the UICollectionView
and leaves out the parts which are yet to be rendered. Is there any that I can achieve it ?
I am using the following extension
func toImage() -> UIImage {
let renderer = UIGraphicsImageRenderer(size: self.bounds.size)
return renderer.image { ctx in
self.drawHierarchy(in: self.bounds, afterScreenUpdates: true)
}
}
Upvotes: 1
Views: 442
Reputation: 535191
Is there any that I can achieve it ?
No, at least not by a simple screen capture. The offscreen cells do not even exist, so there is nothing for you to capture.
Upvotes: 1
Reputation: 104
There are two reasons why your full Collection View is not rendered as an Image.
self.bounds
, which will only capture the content in the specified boundsUpvotes: 0