zoukankan      html  css  js  c++  java
  • iOS 混合开发 —— WebView 问题技巧

    1、图片太大

    - (void)webViewDidFinishLoad:(UIWebView *)webView {
      NSString *js = @"function imgAutoFit() { 
         var imgs = document.getElementsByTagName('img'); 
         for (var i = 0; i < imgs.length; ++i) {
            var img = imgs[i];   
            img.style.maxWidth = %f;   
         } 
      }";
      js = [NSString stringWithFormat:js, [UIScreen mainScreen].bounds.size.width - 20];
      
      [webView stringByEvaluatingJavaScriptFromString:js];
      [webView stringByEvaluatingJavaScriptFromString:@"imgAutoFit()"];
    }
    

      

    2、内容高度

    通过JS来获取高度:document.body.offsetHeight;

    #pragma mark - UIWebViewDelegate
    - (void)webViewDidFinishLoad:(UIWebView *)webView {
      CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] intValue];
      if (self.webViewHeight != height && self.count <= 3) {
        self.webViewHeight = height;
        self.count++;
        
        [self updateUI];
      }
    }
    
    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
      self.webViewHeight = webView.scrollView.contentSize.height;
      return YES;
    }
    

      

    github地址: https://github.com/lc081200/hybirdApp 

  • 相关阅读:
    常用录屏工具
    python常用工具库介绍
    修改anaconda3 jupyter notebook 默认路径
    【转载】面试那些事【三】
    【转载】面试那些事【二】
    【转载】面试那些事【一】
    Myeclipse 激活代码 8.6以前的版本
    ddd
    Java 算法
    Java 水仙花数
  • 原文地址:https://www.cnblogs.com/saytome/p/7141279.html
Copyright © 2011-2022 走看看