2013-10-29 69 views
1

我使用的是UIPageViewController並在它的多個UIWebViews中,我加載所有我的網頁視圖,從之前與此:UIWebView的scalesPageToFit不能正常工作

- (void) createContentPages 
{ 
    NSMutableArray *pageStrings = [[NSMutableArray alloc] init]; 
    for (int i = 0; i < chapters.count; i++) 
    { 
     NSString *path; 
     path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@%@",[arrayDeCapitulos objectAtIndex:i],idioma] ofType:@"txt"]; 
     NSString *arbit; 
     if (path) { 
      arbit = [[NSString alloc]initWithContentsOfFile:arbitPath encoding:NSUTF8StringEncoding error:nil]; 
     } 
     NSString *a; 
     [email protected]"LTR"; 
     if ([idioma isEqualToString:@"h"]) { 
      [email protected]"RTL"; 
     } 
     int size=[[[NSUserDefaults standardUserDefaults]objectForKey:@"preferredSize"]integerValue]; 
     NSString *contentString=[NSString stringWithFormat:@"<html DIR='%@'><head>" 
           "<style>" 
           "*{ padding-bottom:5;font-size:%i;" 
           " font-family:'SBL Hebrew';max-width: %fpx;}" 
           "</style>" 
           "<meta name='viewport' content='width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;' />" 
           "</head>" 
           "<body>" 

           "%@" 

           "</BODY> </HTML>",a,size,self.view.bounds.size.width ,arbit]; 
     [pageStrings addObject:contentString]; 
    } 
    pageContent = [[NSArray alloc] initWithArray:pageStrings]; 
} 

一切正常,除了有時一切都錯了...我已經嘗試了一切,有人有任何想法嗎?

然後在我的其他I類加載的UIWebView

[webView loadHTMLString:dataObject 
       baseURL:[NSURL URLWithString:@""]]; 
[webView setScalesPageToFit:NO]; 
webView.delegate=self; 

-(void)webViewDidFinishLoad:(UIWebView *)webview 
{ 
    CGSize contentSize = webView.scrollView.contentSize; 
    CGSize viewSize = self.view.bounds.size; 
    float rw = viewSize.width/contentSize.width; 
    webView.scrollView.minimumZoomScale = rw; 
    webView.scrollView.maximumZoomScale = rw; 
    webView.scrollView.zoomScale = rw; 
} 

下面是結果:

enter image description here enter image description here

回答

0

我知道它聽到怪異,但通過移動HTML的內容到一個特區做了這份工作。

NSString *contentString=[NSString stringWithFormat:@"<html DIR='%@'><head>" 
       "<style>" 
       "*{ padding-bottom:5;font-size:%i;" 
       " font-family:'SBL Hebrew'}" 

       "</style>" 

       "</head>" 
       "<body>" 
       "<div>%@</div>" 

       "</body> </HTML>",a,size,arbit]; 
0

試試這個

NSString *contentString=[NSString stringWithFormat:@"<html DIR='320px'><head>" 
      "<style>" 
      "*{ padding-bottom:5;font-size:%i;" 
      " font-family:'SBL Hebrew'}" 

      "</style>" 

      "</head>" 
      "<body>" 
      "<div>%@</div>" 

      "</body> </HTML>",size,arbit]; 

你可以設置DIV寬度:320像素;和HTML代碼上的高度100%。