2017-03-23 47 views
-3
- (void)webViewDidFinishLoad:(UIWebView *)webView{ 
    NSString *string = [NSString stringWithFormat:@"document.body.style.zoom = %@;", [UIFont fontWithName:centuryGothicBold size:5]]; 
    [self.longNewsWebView stringByEvaluatingJavaScriptFromString:string]; 
} 

回答

0

終於得到了我的問題的答案很長的研究

- (void)webViewDidFinishLoad:(UIWebView *)webView{ 
[self stopProgressHUD]; 
NSString *cssString = [[[[@"body { font-family:" stringByAppendingString:centuryGothicRegular] stringByAppendingString:@"; font-size:"] stringByAppendingString:[NSString stringWithFormat:@"%ld",normalFont]] stringByAppendingString:@"}\""] ; //1 

NSString *javascriptString = @"var style = document.createElement('style'); style.innerHTML = '%@'; document.head.appendChild(style)"; // 2 
NSString *javascriptWithCSSString = [NSString stringWithFormat:javascriptString, cssString]; // 3 
NSLog(@"javascriptWithCSSString: \n %@", javascriptWithCSSString); 
NSString *loadedContent = [webView stringByEvaluatingJavaScriptFromString:javascriptWithCSSString]; 
NSLog(@"loaded ocntent: %@", loadedContent); 

}

centuryGothicRegular是字體的哪個地方聲明爲常量名之後。 normalFont是也被聲明爲整數常量的字體大小

相關問題