What font does UIWebView
and WKWebView
use by default? I would like to be able to change that. But I don\'t want to do it in the html string, inste
Quick solution for SWIFT 4.2
let fontName = "PFHandbookPro-Regular"
let fontSize = 20
let fontSetting = "<span style=\"font-family: \(fontName);font-size: \(fontSize)\"</span>"
webView.loadHTMLString( fontSetting + myHTMLString, baseURL: nil)
span is an inline element, meaning that it can be on a line with other elements
Just prefix a <font face>
tag to your string before loading into the webView.
NSString *body = [plist objectForKey:@"foo"];
NSString *htmlString =
[NSString stringWithFormat:@"<font face='GothamRounded-Bold' size='3'>%@", body];
[webView loadHTMLString:htmlString baseURL:nil];
There is the swift 3 solution :
func webViewDidFinishLoad(_ webView: UIWebView) {
webView.stringByEvaluatingJavaScript(from: "document.getElementsByTagName('body')[0].style.fontFamily =\"-apple-system\"")
}
I have just put the default iOS font for this example