0

当我在 uiwebview 中显示 epub 时,我可以看到有 480 像素以下的行,所以我如何将内容大小高度限制为 450 像素并添加 50 像素的底部边距。目前我正在使用以下代码添加总填充我不知道如何限制 uiwebview 的内容高度?

NSString *padding = @"document.body.style.padding='15px 15px 15px 15px';";
[webView stringByEvaluatingJavaScriptFromString:padding];

请帮我

我尝试使用此代码获取内容大小,但它返回的值为 14783

webView.scrollView.ContentSize.height;然后我得到 14783

4

2 回答 2

1

试着用这个...

CGSize contentSize = CGSizeMake([[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollWidth;"] floatValue],
                                [[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"] floatValue]);

已编辑…………

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    CGRect frame = webView.frame;

    frame.size.height = 5.0f;

    webView.frame = frame;
}


- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    CGSize mWebViewTextSize = [webView sizeThatFits:CGSizeMake(1.0f, 1.0f)];  // Pass about any size

    CGRect mWebViewFrame = webView.frame;


    mWebViewFrame.size.height = mWebViewTextSize.height;

    webView.frame = mWebViewFrame;


    //Disable bouncing in webview
    for (id subview in webView.subviews)
    {
        if ([[subview class] isSubclassOfClass: [UIScrollView class]])
        {
            [subview setBounces:NO];
        }
    }
}
于 2013-06-03T04:49:46.180 回答
0

试试这个代码:

- (void)webViewDidFinishLoad:(UIWebView *)webView1
{
      NSString  *totalHeight;

        totalHeight = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"foo\").offsetHeight;"];

         if([totalHeight intValue] >= 450)
         {
            [webView setFrame:CGRectMake(0, 0, webView.frame.size.width, 450)];
         }
         else
         {
          [webView setFrame:CGRectMake(0, 0, webView.frame.size.width, [totalHeight floatValue])];
         }
}

我希望它对你有帮助。

于 2013-06-03T04:52:01.560 回答