1. 程式人生 > >iOS 實現webview不滾動,顯示所有內容

iOS 實現webview不滾動,顯示所有內容

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

;

3,

遵守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.scrollSuperViewcontentSize 高度顯示自己可以定
self.scrollSuperView.contentSize = CGSizeMake(0height1+SCREEN_HEIGHT); 6.

這樣便實現了webview不滾動,也能實現內容全部顯示。