1

How do we get the height value of HTML content from UIViewRepresentable?

I want to get a height value from the HTML content that I have loaded to WebKit, How do I get that?

this is my code.

struct HTMLView: UIViewRepresentable {
    let htmlContent: String

    func makeUIView(context: Context) -> WKWebView {
        return WKWebView()
    }

    func updateUIView(_ uiView: WKWebView, context: Context) {
        let anuphanRegular = getDataString(otf: "Anuphan-Regular")
        
        let htmlString = """
        <!doctype html>
        <meta charset="utf-8"/>

        <html>
            <head>
                <style>
                    @font-face {
                        font-family: 'Anuphan';
                        src: url('data:font/otf;base64,\(anuphanRegular)') format('opentype');
                    }
                </style>
            </head>
            <body>
                <div class="container">
                    <div class="element">
                        <span class="custom">\(htmlContent)</span>
                    </div>
                </div>
            </body>
        </html>
        """
        
        uiView.loadHTMLString(htmlString, baseURL: nil)
    }
}
Mixko
  • 471
  • 1
  • 3
  • 9
  • This might help https://stackoverflow.com/questions/27515236/how-to-determine-the-content-size-of-a-wkwebview – lastbreath Jan 15 '23 at 21:07

0 Answers0