2012-05-11 83 views
0

我把Uiwebview放在UIscrollview中,因爲在uiwebview之後我想用PageController顯示一些圖片。stringByEvaluatingJavaScriptFromString承認webview內容的高度

我使用這行代碼。

-(void)webViewDidFinishLoad:(UIWebView *)webView{ 
    if (webView!=WebView)return; 
    float h; 

    NSLog(@"web view is %f high", WebView.frame.size.height); 
    NSString *heightString = [WebView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"body\").offsetHeight;"]; 
    NSLog(@"web content is %@ high",heightString); 

    h = [heightString floatValue] +12.0f; 
    WebView.frame = CGRectMake(WebView.frame.origin.x, WebView.frame.origin.y, WebView.frame.size.width, h); 

    h = WebView.frame.origin.y + h + 20; 
    [ScrollView setContentSize:CGSizeMake(320, h)]; 


} 

Web view is %f high不起作用,它不會reconize web視圖的高度,沒有人知道我是如何解決這一問題?這是因爲我使用[WebView loadHTMLString:html baseURL:nil];

和:NSString *heightString = [WebView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"body\").offsetHeight;"];

NSString *html = [NSString stringWithFormat:@"<html><head><!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><style>body { font: normal 13px helvetica; color: #565656; } </style></head><body><p>%@</p></body></html> ",text]; 


[WebView loadHTMLString:html baseURL:nil]; 

回答

1

嘗試

NSString *heightString = [Bericht stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"]; 

祝你好運, 彌敦道

+0

嗨,請你幫我在這個鏈接http://stackoverflow.com/questions/10793698/how-to-make-image-maps-clickable-using-uiwebview-in-iphone –

0

UIWebView中已經包含了一個滾動視圖,你爲什麼再次將其添加爲一個子視圖。檢查Apple的文檔here

+1

因爲他想要的顯示在他的UIWebView(UIPageControl)的圖像? – Nathan