2012-02-28 57 views
2

我在我的應用程序中顯示html郵件。但它並沒有將圖像拉伸到全尺寸,而蘋果的郵件應用程序則完成了。見下面的截圖。如何蘋果是什麼想法如何實現這一目標?UIScrollView中的UIWebView不能正確顯示內容?

  1. 我的應用程序的Web視圖

enter image description here

蘋果的郵件應用

enter image description here

+0

你可以發佈一個鏈接到示例網頁嗎?你能發佈你如何在webview中嵌入html內容嗎? – alex 2014-04-09 18:36:11

回答

1

我知道這並不能回答你的問題,但蘋果明確地警告不要嵌入UIWebViews中在UIWebView類參考中的UIScrollViews中

Important You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled. 

但是對於它的價值,您是否嘗試過UIWebView的scalesPageToFit屬性?

+0

我沒有在scrollView中嵌入UIWebView。是的,我正在使用scalePagesToFit = TRUE; – 2012-03-01 04:10:42

0

不知道我哪裏有這個,但它是在我的筆記。
你需要做一點JS工作,以便它適合一旦它被渲染。

#pragma mark - 
#pragma mark UIWebViewDelegate methods 
-(void)webViewDidFinishLoad:(UIWebView *)webView{ 
if (webView!=bioWebView)return; 

float h; 

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

h = [heightString floatValue] +12.0f; // convert from string to float plus some extra points because calculation is sometimes one line short 

bioWebView.frame = CGRectMake(bioWebView.frame.origin.x, bioWebView.frame.origin.y, bioWebView.frame.size.width, h); 

// get bottom of text field 
h = bioWebView.frame.origin.y + h + 70; // extra 70 pixels for UIButton at bottom and padding. 
[scrollView setContentSize:CGSizeMake(320, h)]; 

/* 

    position button code here.... 

    */ 

}