iOS 實現webview不滾動,顯示所有內容
阿新 • • 發佈:2019-02-04
self.first_webview 為:web view height1 為:web view內容高度 self.scrollSuperView 為:滾動式圖scrollview
1.
首先我們要在底部放一個scrollview,在上面放置一個webview,接下來便是禁止webview滾動。
2.
實現web view不滾動
UIScrollView *first_tempView = (UIScrollView *)[self.first_webview.subviewsobjectAtIndex:0];
first_tempView.scrollEnabled = NO
遵守web view的協議
4.
計算web view內容的高度
- (void)webViewDidFinishLoad:(UIWebView *)webView{
height1 = [[self.first_webviewstringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"] floatValue];NSLog(@"self.first_webview = %f",height1);
}
5. 獲取到實際高度後,設定self.scrollSuperView的contentSize 高度顯示自己可以定這樣便實現了webview不滾動,也能實現內容全部顯示。