2014-09-26 2 views
0

У меня есть UIWebview.UIWebview иногда увеличивает масштаб страницы, а иногда нет

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 ; 



} 

Такое же веб-представление дает другой результат, как вы можете видеть ниже. Я знаю, что могу установить scalespageTofit. Но потом я теряю свой шрифт.

enter image description here

Может кто-нибудь помочь мне с этим?

ответ

0

Пожалуйста, попробуйте это webViewDidFinishLoad метод

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

Если это оленья кожа работа, то проверить webView's autoresing свойство

Смежные вопросы