I\'m generating an UIWebView into my viewDidLoad method, with a tiny size (let\'s say something like 50x70). And then I put it into a super UIView.
I\'d like to ma
For those, who faced same problem, you can turn off the UIWebView native scrolling by
self.webView.scrollView.scrollEnabled = NO;
and add a separate scrollView
which will handle scrolling and zooming instead of webView
's native scroll.
Next implement
- (void) webViewDidFinishLoad:(UIWebView *)webView
{
CGRect frame = _webView.frame;
CGSize fittingSize = [_webView sizeThatFits:_webView.scrollView.contentSize];
frame.size = fittingSize;
_webView.frame = frame;
self.scrollView.contentSize = self.webView.scrollView.contentSize;
}
to set proper webView
frame.
Hope this helps someone. Good coding!
For Swift 3, I have achieved the same with
DispatchQueue.main.async {
if let finalURL = URL(string: urlString) {
let request = URLRequest(url: finalURL)
// self.webView.sizeToFit()
self.webView.scalesPageToFit = true
self.webView.contentMode = .scaleAspectFit
self.webView.loadRequest(request)
}
}