How to change UIWebView or WKWebView default font

前端 未结 9 1293
陌清茗
陌清茗 2020-12-08 01:14

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

9条回答
  •  鱼传尺愫
    2020-12-08 01:31

    In case someone is looking for a solution in Swift 3, I used this (based on jterry's answer):

    let font = UIFont.init(name: "Name-of-your-font", size: theSize)
    self.newsWebView.loadHTMLString("\(yourString)", baseURL: nil)
    

    Be aware that here I'm not making sure the font isn't nil. A nil check could be added before loading the HTML string. Here I'm also changing the color of the font by adding the color option in the style of the span. This is completely optional.

提交回复
热议问题