HTML, CSS view in Swift

2023. 3. 16. 11:48Frontend/Swift

struct HTMLStringView: UIViewRepresentable {
    let htmlContent: String
    let cssStyle  = """
        <style>
            .클래스명1 {
              CSS 스타일
            }
            .클래스명2 {
              CSS 스타일
            }
        </style>
        """

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

    func updateUIView(_ uiView: WKWebView, context: Context) {
        uiView.loadHTMLString( cssStyle + htmlContent, baseURL: nil)
    }
}

참고 자료

https://stackoverflow.com/questions/56892691/how-to-show-html-or-markdown-in-a-swiftui-text

 

How to show HTML or Markdown in a SwiftUI Text?

How can I set a SwiftUI Text to display rendered HTML or Markdown? Something like this: Text(HtmlRenderedString(fromString: "<b>Hi!</b>")) or for MD: Text(MarkdownRenderedString(

stackoverflow.com

 

'Frontend > Swift' 카테고리의 다른 글

shadow with radius  (1) 2023.04.18
ISOstring to date  (2) 2023.04.18
StoryBoard vs. SwiftUI  (0) 2023.03.21