Post

Replies

Boosts

Views

Activity

Reply to How to Render a WKWebView() to png-file (iOS16)?
Thank you, NaimadDev, for the quick reply. Got 1 step forward. I am using struct WebView : UIViewRepresentable { } to load my html.site with WKWebView(). Within the Webview I have a Coordinator to trigger once website is fully loaded. struct WebView : UIViewRepresentable { ...     @Binding var showLoading: Bool     func makeCoordinator() -> Coordinator {         Coordinator(didStart: {             showLoading = true         }, didFinish: {             showLoading = false             saveWebView(EmulatorView())         })     } ...      Once didFinish, I call the WebView extension function saveWebView with the EmulatorView, The EmulatorView contains my Website called with WebView(showLoading: $showLoading) extension WebView {     @MainActor func saveWebView(_ view: EmulatorView) {         let renderer = ImageRenderer(content: view)         renderer.scale = 3.0         renderer.isOpaque = false         if let image = renderer.uiImage {             if let data = image.pngData() {                 if let filedirectory = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents").appendingPathComponent("\(selectedPreviewTheme)") {                     if (FileManager.default.fileExists(atPath: filedirectory.path, isDirectory: nil)) {                         let filepath = filedirectory.appendingPathComponent("01_Screenshot_\(selectedPreviewTheme).png")                         try? data.write(to: filepath)                     }                 }             }         }     } } The EmulatorView will be rendered, BUT unfortunately just a 216x216 png with my Emulator .background(Color("background2")). If I use another view from my app, e.g. the OnboardingView(), this one will be rendered fine. Any ideas are highly appreciated Eric
Dec ’22