这里就是你要做的:
在拥有web视图您的UI控制器,使它成为一个UIWebViewDelegate
。然后,您可以设置要加载的URL,将委托作为控制器:
NSString *urlAddress = @"http://dl.dropbox.com/u/50941418/2-build.html";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
webView.delegate = self;
最后落实webViewDidFinishLoad
:正确设置缩放级别:
此选项将适用于从iOS的5.0和>
- (void)webViewDidFinishLoad:(UIWebView *)theWebView{
CGSize contentSize = theWebView.scrollView.contentSize;
CGSize viewSize = theWebView.bounds.size;
float rw = viewSize.width/contentSize.width;
theWebView.scrollView.minimumZoomScale = rw;
theWebView.scrollView.maximumZoomScale = rw;
theWebView.scrollView.zoomScale = rw;
}
我希望这有助于...
选项B,你可以尝试改变日e HTML(这个例子完成了这项工作,但从HTML解析的角度来看,它并不完美。我只想说明我的观点。它确实适用于您的示例,也可能适用于大多数情况。 40的插图可能会以编程方式检测到,我没有试图研究。
NSString *urlAddress = @"http://dl.dropbox.com/u/50941418/2-build.html";
NSURL *url = [NSURL URLWithString:urlAddress];
NSString *html = [NSString stringWithContentsOfURL:url encoding:[NSString defaultCStringEncoding] error:nil];
NSRange range = [html rangeOfString:@"<body"];
if(range.location != NSNotFound) {
// Adjust style for mobile
float inset = 40;
NSString *style = [NSString stringWithFormat:@"<style>div {max-width: %fpx;}</style>", self.view.bounds.size.width - inset];
html = [NSString stringWithFormat:@"%@%@%@", [html substringToIndex:range.location], style, [html substringFromIndex:range.location]];
}
[webView loadHTMLString:html baseURL:url];
的可能的复制[UIWebView中禁用缩放时scalesPageToFit是ON](http://stackoverflow.com/questions/9062195/uiwebview-disable-zooming-when-scalespagetofit-is-on) –
试过页已经,没有工作。 – tgwaste
你可以添加一些更多的滚动相关的代码,我反应重复 –