Skip to content

Instantly share code, notes, and snippets.

@VictorZhang2014
Created December 15, 2020 14:10
Show Gist options
  • Save VictorZhang2014/b28af4240e1c8f0fd363d0023bc8a45c to your computer and use it in GitHub Desktop.
Save VictorZhang2014/b28af4240e1c8f0fd363d0023bc8a45c to your computer and use it in GitHub Desktop.
Get a snapshot or screenshot of visible UICollectionViewCell in UICollectionView - Swift 5.2
extension UICollectionView {
// Snapshot of UICollectionView, wherever you scroll, it captures the visible cells on screen as an image
func snapshot() -> UIImage? {
UIGraphicsBeginImageContextWithOptions(self.frame.size, false, 0)
UIGraphicsBeginImageContext(bounds.size)
self.drawHierarchy(in: frame, afterScreenUpdates: true)
let screenshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return screenshot
}
}
@VictorZhang2014
Copy link
Author

UICollectionView滑动到哪里,就捕捉那一片的可视视图截屏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment