UIScrollView中的UIWebView无法正确显示内容?

时间:2012-02-28 11:52:33

标签: html ios4 uiwebview

我在我的应用中显示html邮件。但它并没有将图像拉伸到完整尺寸,而苹果的邮件应用程序确实如此。看下面的截图。苹果有什么想法如何实现这个目标?

  1. 我的应用程序网页视图
  2. enter image description here

    Apple的邮件应用程序

    enter image description here

3 个答案:

答案 0 :(得分:1)

我知道这不能回答你的问题,但是Apple明确警告不要在UIWebView类参考中将UIWebViews嵌入到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属性?

答案 1 :(得分:1)

您可以尝试在HTML中使用视口元标记。即使您在加载HTML之前无法修改HTML,也可以在事后添加/调整此标记。

我在这里回答了一个关于如何实现这个目标的问题:

UIWebView -- load external website, programmatically set initial zoom scale, and allow user to zoom afterwards

答案 2 :(得分: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.... 

    */

}