Reputation: 901
I created a webview programmatically and I am unable to enable scrolling in this view.
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 !
Upvotes: 13
Views: 22718
Reputation: 735
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.
2) Implement following method.
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
}
Upvotes: 0
Reputation: 631
Removing from Interface Builder and adding via code did for me. For some reason in IB it wasn't scrolling.
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 64, 320, 50)];
[self.view addSubview: webView];
Upvotes: -1
Reputation: 6490
To enable scrolling,
webview.scrollView.scrollEnabled = TRUE;
and instead of writing this,
webView.contentMode = UIViewContentModeScaleAspectFit;
write this,
webview.scalesPageToFit = TRUE;
Upvotes: 23