2018年4月25日 星期三

獲取UIWebView的內容高度

// 直接抓
CGSize newSize = [webView.scrollView contentSize];
webViewHeightConstraint.constant = newSize.height;

// 如果是單純本地端的html,這樣比較準
CGFloat webViewHeight = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];
textViewHeightConstraint.constant = webViewHeight;

沒有留言:

張貼留言