swift 3.0 webView缩放

viewDidLoad里面

      webView.delegate = self
      self.view.backgroundColor = UIColor.white
      webView.scrollView.bounces = true
      webView.scalesPageToFit = true
      webView.isUserInteractionEnabled = true
      webView.autoresizingMask = UIViewAutoresizing.flexibleWidth
      webView.autoresizingMask = UIViewAutoresizing.flexibleHeight
      webView.isMultipleTouchEnabled  = true
      webView.scrollView.isScrollEnabled = true
func webViewDidFinishLoad(_ webView: UIWebView) {
// 这是给网页里面的内容注入js代码  这个让网页内容缩放
    let jsMeta = "var meta = document.createElement('meta');meta.content='width=device-width,initial-scale=1.0,minimum-scale=.5,maximum-scale=3';meta.name='viewport';document.getElementsByTagName('head')[0].appendChild(meta);"
    webView.stringByEvaluatingJavaScript(from: jsMeta)
 }

你可能感兴趣的:(swift 3.0 webView缩放)