search

Home  >  Q&A  >  body text

objective-c - iOS开发,如何让UIWebView高度自适应内容(HTML文本)?

PHPzPHPz2771 days ago611

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-04-18 09:41:47

    Does the height of the frame of UIWebview change according to the internal html?

    My approach is generally to let the webview load HTML first, and then the controller becomes the delegate of the webview.
    In the webViewDidLoad method, get the height of the webview after loading through js, and then refresh the page. At this time, set the frame for the webView .size.height can be equal to the height you obtained through js before

    _webViewHeight = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];

    reply
    0
  • Cancelreply