我有一个带有pdf文件的UIWebView。它工作正常。但是如何启用缩放pdf文件呢?
答案 0 :(得分:228)
确保选中“Scales page to fit”
答案 1 :(得分:45)
您可以通过编程方式使用webView.scalesPageToFit=YES;
如果您在xib中使用而不仅仅是click the check box "Scaling" scales Page to fit
答案 2 :(得分:27)
此逻辑用于缩放UIWebView,无需在UIScrollView上添加UIWebView
webView.scalesPageToFit = YES;
唯一的问题是,它会改变字体大小的初始内容,但我找到了其他选项
将<UIWebViewDelegate, UIScrollViewDelegate>
添加到 .h文件
创建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上测试 - 使用Xcode 5.1.1和iOS 6.1及更高版本的10.9.3。
我希望这会对你有所帮助。 :)
答案 3 :(得分:22)
答案 4 :(得分:13)
答案 5 :(得分:5)
你必须设置scalesPageToFit = YES,以便在UIWebView上进行任何捏合和缩放。它适合我。