I created a webview programmatically and I am unable to enable scrolling in this view.
我以编程方式创建了一个webview,我无法在此视图中启用滚动。
How do I enable scrolling?
如何启用滚动?
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,40, 325, 1000)];
webView.contentMode = UIViewContentModeScaleAspectFit;
[webView setBackgroundColor:[UIColor clearColor]];
[webView loadHTMLString:html baseURL:nil];
[self.view insertSubview:webView atIndex:0];
Thanks In Advance !
提前致谢 !
3 个解决方案
#1
23
To enable scrolling,
要启用滚动,
webview.scrollView.scrollEnabled = TRUE;
and instead of writing this,
而不是写这个,
webView.contentMode = UIViewContentModeScaleAspectFit;
write this,
写这个,
webview.scalesPageToFit = TRUE;
#2
0
Removing from Interface Builder and adding via code did for me. For some reason in IB it wasn't scrolling.
从Interface Builder中删除并通过代码添加对我来说。出于某种原因,在IB中它没有滚动。
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 64, 320, 50)];
[self.view addSubview: webView];
#3
0
These are the possible solutions.
这些是可能的解决方案。
i) You webview may be large in size than you expected or your content is lesser than the webview size.
i)您的webview可能比预期的大,或者您的内容小于webview大小。
2) Implement following method.
2)实施以下方法。
func webViewDidFinishLoad(webView: UIWebView)
{
appDelegate.hideLoadingView()
let res: NSString = webView.stringByEvaluatingJavaScriptFromString("document.body.offsetHeight;")!
let h: CGFloat = CGFloat(res.integerValue)
agreementContentView.scrollView.contentSize = CGSizeMake(webView.frame.size.width, h + 50); // Offset if required
}
#1
23
To enable scrolling,
要启用滚动,
webview.scrollView.scrollEnabled = TRUE;
and instead of writing this,
而不是写这个,
webView.contentMode = UIViewContentModeScaleAspectFit;
write this,
写这个,
webview.scalesPageToFit = TRUE;
#2
0
Removing from Interface Builder and adding via code did for me. For some reason in IB it wasn't scrolling.
从Interface Builder中删除并通过代码添加对我来说。出于某种原因,在IB中它没有滚动。
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 64, 320, 50)];
[self.view addSubview: webView];
#3
0
These are the possible solutions.
这些是可能的解决方案。
i) You webview may be large in size than you expected or your content is lesser than the webview size.
i)您的webview可能比预期的大,或者您的内容小于webview大小。
2) Implement following method.
2)实施以下方法。
func webViewDidFinishLoad(webView: UIWebView)
{
appDelegate.hideLoadingView()
let res: NSString = webView.stringByEvaluatingJavaScriptFromString("document.body.offsetHeight;")!
let h: CGFloat = CGFloat(res.integerValue)
agreementContentView.scrollView.contentSize = CGSizeMake(webView.frame.size.width, h + 50); // Offset if required
}