I want to use custom fonts in a WKWebView
.
I use insertCSSString(into webView: WKWebView)
, but as soon as I add "@font-face{font-family: 'Roboto-BlackItalic'; url('Roboto-BlackItalic.ttf') format('truetype');}"
to the string the css appears not not be evaluated (in this example the colour of any text does not change to red).
The approach is taken from Using custom fonts in WKWebView
So the question is - how can I use custom fonts with this approach. I have tried the following:
extension DetailViewController {
func insertCSSString(into webView: WKWebView) {
let cssString = "@font-face{font-family: 'Roboto-BlackItalic'; url('Roboto-BlackItalic.ttf') format('truetype');} body { font-size: 20px; color: red; background-color: clear; } htesttwo {color: black; }"
let jsString = "var style = document.createElement('style'); style.innerHTML = '\(cssString)'; document.head.appendChild(style);"
webView.evaluateJavaScript(jsString, completionHandler: nil)
}
}