wkwebview加载HTML标签适配

2022-11-07  本文已影响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

上一篇 下一篇

猜你喜欢

热点阅读