2014-09-26 81 views
0

我有以下UIWebviewUIWebview有時會放大頁面,有時候不會

webNieuws = [[UIWebView alloc]initWithFrame:CGRectMake(10, height,300, 400)]; 
     [webNieuws setScalesPageToFit:NO]; 
     [[webNieuws scrollView] setBounces: NO]; 
     webNieuws.delegate = self; 
     NSString *myDescriptionHTML = [NSString stringWithFormat:@"<html> \n" 
             "<head> \n" 
             "<style type=\"text/css\"> \n" 
             "body {font-family: \"%@\"; size=\"12\" COLOR:#111111; background-color:transparent;}\n" 
             "</style> \n" 
             "</head> \n" 
             "<body>%@</body> \n" 
             "</html>", @"MyriadPro-Regular",_hotnews.hot_content]; 
     NSLog(@"Hot news content is %@",_hotnews.hot_content); 


     [webNieuws setBackgroundColor:[UIColor yellowColor]]; 
     [webNieuws setOpaque:NO]; 

     [webNieuws loadHTMLString:myDescriptionHTML baseURL:nil]; 
     [scrollView addSubview:webNieuws]; 


- (void)webViewDidFinishLoad:(UIWebView *)aWebView { 
    CGRect frame2 = aWebView.frame; 
    frame2.size.height = 1; 
    frame2.origin.y = height; 
    aWebView.frame = frame2; 
    CGSize fittingSize = [aWebView sizeThatFits:CGSizeZero]; 
    frame2.size = fittingSize; 
    CGFloat webHeight = [[aWebView stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight;"] floatValue]; 
    frame2.size.height =webHeight; 

    aWebView.frame = frame2; 
    NSLog(@"Height is %f",webHeight); 


    float newHeight2 = 30 + webHeight; 
    NSLog(@"new height header is %f",newHeight2); 



    [scrollView setFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)]; 
    [scrollView setContentSize:CGSizeMake(self.view.frame.size.width,newHeight2 + 320)]; 
    scrollView.bounces = NO ; 



} 

相同的webview會給出不同的結果,如下圖所示。我知道我可以設置scalespageTofit。但是,然後我失去了我的字體大小。

enter image description here

有人可以幫助我?

回答

0

webViewDidFinishLoad方法

NSString *javascriptCommand = [NSString stringWithFormat:@"document.body.style.zoom = 1.0;"]; 
[aWebView stringByEvaluatingJavaScriptFromString:javascriptCommand]; 

試試這個如果不列入工作然後檢查你的webView's autoresing財產

相關問題