Answers:
确保选中“缩放页面以适合”
您可以以webView.scalesPageToFit=YES;
编程方式使用
如果您在xib中使用的不只是 click the check box "Scaling" scales Page to fit
此逻辑用于缩放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-10.9.3上使用Xcode 5.1.1和iOS版本6.1及更高版本进行测试。
希望对您有帮助。:)