In this tutorial, We will be converting ScrollView’s content into a UIImage. First, we will convert any view into the UIImage then we will extend the same logic to screenshot the entire Scroll view content.
Create an extension on SwiftUI’s view, which takes the position of part of the view we need to convert into an image. We will create a dummy UIHostingViewController with the given frame. From UIHostingView controller, we will access UIKit’s view.
2. Getting Image from UIKit’s UIView: For this, we are going to use simple core graphics apis like following:
extension UIView { var screenShot: UIImage { let rect = self.bounds UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0) let context: CGContext = UIGraphicsGetCurrentContext()…