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 ;
}
相同的webview會給出不同的結果,如下圖所示。我知道我可以設置scalespageTofit
。但是,然後我失去了我的字體大小。
有人可以幫助我?