這裏就是你要做的:
在擁有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
你可以添加一些更多的滾動相關的代碼,我反應重複 –