iOS에서 html텍스트 표시하기

NU·2022년 5월 6일
0

GitHub

목록 보기
1/1

RichText

많은곳에서 사용되는 상황은 아니지만
특정한 상황에서 html텍스트를 표시해야될 경우가 있다

그래서 라이브러리로 만들었다.
깃허브 링크

SwiftUI로 만들었기 때문에 iOS13이상인 경우에만 사용이 가능하다

샘플코드

import SwiftUI
import RichText

struct RichText_Test: View {
    @State private var  html = ""
    
    var body: some View {
       ScrollView{
            RichText(html: html)
                .lineHeight(170)
                .imageRadius(12)
                .fontType(.system)
                .colorScheme(.automatic)
                .colorImportant(true)
                .linkOpenType(.SFSafariView)
                .linkColor(ColorSet(light: "#007AFF", dark: "#0A84FF"))
                .placeholder {
                    Text("loading")
                }
        }
    }
}

struct RichText_Test_Previews: PreviewProvider {
    static var previews: some View {
        RichText_Test()
    }
}

추가 설명

RichText에서 html만 필수고
나머지는 옵션이다

필요하다면 값을 변경하거나, 삭제를 해도된다.

profile
2년차 iOS개발자 입니다

0개의 댓글