I'm in need of rendering a html string in my swiftui app.
I found this: How to show HTML or Markdown in a SwiftUI Text?
But I tried every single solution there and I get a blank screen!
This is my code:
import SwiftUI
import WebKit
struct HTMLStringView: UIViewRepresentable {
let htmlContent: String
func makeUIView(context: Context) -> WKWebView {
return WKWebView()
}
func updateUIView(_ uiView: WKWebView, context: Context) {
uiView.loadHTMLString(htmlContent, baseURL: nil)
}
}
struct audioInfoView: View {
let longDetails: String
var body : some View{
ScrollView{
ZStack{
HTMLStringView(htmlContent: "<p>\(longDetails)</p>")
//Text(longDetails)
}.padding()
}.padding(.top,50)
}
}
The let longDetails: String
is a string with html tags that's being passed on from another view.
If I do Text(longDetails)
, I can see the text and all the html tags but when I do HTMLStringView(htmlContent: "<p>\(longDetails)</p>")
, I see nothing and it only displays a blank screen!
what am I doing wrong?