当我在 uiwebview 中显示 epub 时,我可以看到有 480 px 以下的行,那么我如何将内容大小高度限制为 450 px 并添加 50px 的底部边距。目前我正在添加总填充使用以下代码我不知道如何限制 uiwebview 的内容高度?
NSString *padding = @"document.body.style.padding='15px 15px 15px 15px';";
[webView stringByEvaluatingJavaScriptFromString:padding];
请帮助我
我尝试使用此代码来获取内容大小,但它返回的值是 14783
webView.scrollView.ContentSize.height;
然后我得到 14783
最佳答案
尝试在...上使用它
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];
}
}
}
关于javascript - 如何获取webview当前的内容大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16890130/