码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 混合开发 —— WebView 问题技巧

时间:2017-07-09 14:46:56      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:get   bool   art   height   sel   amp   java   lua   contents   

 

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;
}

  

 

iOS 混合开发 —— WebView 问题技巧

标签:get   bool   art   height   sel   amp   java   lua   contents   

原文地址:http://www.cnblogs.com/saytome/p/7141279.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!