美文网首页
wkwebview加载HTML标签适配

wkwebview加载HTML标签适配

作者: 奋斗的遗忘人 | 来源:发表于2022-11-07 10:18 被阅读0次

适配标椎: 可自动换行,自动匹配屏幕的宽度, 图片自适应适配代码如下

 //加标签头适配 -->self.htmlStr就是你的html字符串
        let head = "<head>" + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">" + "<style>img{max-width: 100%; width:auto; height:auto;} body{word-break:break-all;}</style>" + "</head>"
        let contentStr = "<html>" + head + self.htmlStr + "</html>"
        self.h5WebView.loadHTMLString(contentStr, baseURL: nil)

其实就是在html的头部加个适配head

相关文章

网友评论

      本文标题:wkwebview加载HTML标签适配

      本文链接:https://www.haomeiwen.com/subject/uzrwtdtx.html