Reputation: 31
I have to display several HTML-Content-Strings using SwiftUI. For rendering the HTML-Content I "borrowed" one of the standard solutions that wraps a WKWebCiew()
in an UIViewRepresentable
context.
Unfortunately, the view consumes to much vertical space. The view is just to large.
import SwiftUI
import WebKit
struct HTMLText: UIViewRepresentable {
let htmlContent: String
func makeUIView(context: Context) -> WKWebView {
return WKWebView()
}
func updateUIView(_ uiView: WKWebView, context: Context) {
uiView.loadHTMLString(htmlContent, baseURL: nil)
}
}
let htmlContent1 = """
<ul>
<li> Item 1
<li> Item 2
<li> Item 3
<li> Item 4
</ul>
"""
struct ContentView: View {
var body : some View {
VStack (alignment: .leading){
Text("Above")
HTMLText(htmlContent: htmlContent1)
Text("Middle")
HTMLText(htmlContent: htmlContent1)
Text("Below")
}.padding()
}
}
#Preview {
ContentView()
}
Upvotes: 0
Views: 44