Skip to content

Commit

Permalink
Merge pull request #22 from NuPlay/custom_fonts
Browse files Browse the repository at this point in the history
🐛 Custom fonts bug fix
  • Loading branch information
NuPlay authored Oct 6, 2022
2 parents 247a88b + 96e1b89 commit 48b840c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,35 @@ struct RichText_Test_Previews: PreviewProvider {
}
```

## Custom Font
```swift
import SwiftUI
import RichText

struct RichText_Test: View {
@State private var html = ""

var body: some View {
ScrollView{
RichText(html: html)
.fontType(.customName("Noto Sans"))
.customCSS("""
@font-face {
font-family: 'Noto Sans';
src: url("NotoSans-Regular.ttf") format('truetype');
}
""")
}
}
}

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

## Sample Text
<details>
<summary>Click</summary>
Expand Down
6 changes: 4 additions & 2 deletions Sources/RichText/Views/Webview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ struct WebView: UIViewRepresentable {
webview.scrollView.isScrollEnabled = false

DispatchQueue.main.async {
webview.loadHTMLString(generateHTML(), baseURL: nil)
let bundleURL = Bundle.main.bundleURL
webview.loadHTMLString(generateHTML(), baseURL: bundleURL)
}

webview.isOpaque = false
Expand All @@ -44,7 +45,8 @@ struct WebView: UIViewRepresentable {

func updateUIView(_ uiView: WKWebView, context: Context) {
DispatchQueue.main.async {
uiView.loadHTMLString(generateHTML(), baseURL: nil)
let bundleURL = Bundle.main.bundleURL
uiView.loadHTMLString(generateHTML(), baseURL: bundleURL)
}
}

Expand Down

0 comments on commit 48b840c

Please sign in to comment.