启用缩放/捏UIWebView
我有一个pdf文件的UIWebView。 它工作正常。 但是,我怎样才能启用缩放PDF文件?
确保您选中了“缩放页面以适合”
你可以使用webView.scalesPageToFit=YES; 编程 
 如果您在xib中使用,则只需click the check box "Scaling" scales Page to fit 
这个缩放UIWebView的逻辑,不需要在UIScrollView上添加UIWebView
 那么唯一的问题是webView.scalesPageToFit = YES; 是,它会改变字体大小的初始内容,但我发现其他选项 
 将<UIWebViewDelegate, UIScrollViewDelegate>添加到您的.h文件 
 创build你的UIWebView. 
 self.mWebview = [[UIWebView alloc] init]; self.mWebview.delegate = self; /// set delegate method of UIWebView self.mWebview.frame = CGRectMake(0, 35, self.view.bounds.size.width, self.view.bounds.size.height - 80); // set frame whatever you want.. [self.mWebview setOpaque:NO]; self.mWebview.backgroundColor = [UIColor clearColor]; [self.view addSubview:self.mWebview]; 
加载HTML文件/内容。
 NSString* htmlString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"File Name"ofType:@"html"] encoding:NSUTF8StringEncoding error:nil]; [self.mWebview loadHTMLString:htmlString baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]]; #pragma mark - #pragma mark - Webview Delegate Methods - (void) webViewDidFinishLoad:(UIWebView *)webView { webView.scrollView.delegate = self; // set delegate method of UISrollView webView.scrollView.maximumZoomScale = 20; // set as you want. webView.scrollView.minimumZoomScale = 1; // set as you want. //// Below two line is for iOS 6, If your app only supported iOS 7 then no need to write this. webView.scrollView.zoomScale = 2; webView.scrollView.zoomScale = 1; } #pragma mark - #pragma mark - UIScrollView Delegate Methods - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale { self.mWebview.scrollView.maximumZoomScale = 20; // set similar to previous. } 
注意:我必须在Mac OS X – 10.9.3上使用Xcode 5.1.1和iOS 6.1以及后者进行testing。
我希望这会对你有所帮助。 🙂
我知道这个问题是相当古老的,但是对于每个使用故事板的人来说,它都是一个可视化的答案。 只需在WebView的属性检查器中选中此框即可:
  
 
如果你想以编程方式做,然后使用
 webView.scalesPageToFit = YES; 
 如果你正在使用故事板,那么你必须打勾checkbox“缩放”比例页面适合  
 
你必须设置scalesPageToFit = YES对于任何捏和缩放工作在UIWebView。 它为我工作。