[英]how to resize the wkwebview font size?
How to change the font size of WKWebView
irrespective of the webkit content in iOS programming? 无论iOS编程中的Webkit内容如何,如何更改
WKWebView
的字体大小?
I am using [Webview stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"resizeText(%lu)",(unsigned long)fontSize]];
我正在使用
[Webview stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"resizeText(%lu)",(unsigned long)fontSize]];
But it doesn't make any changes to the web view font size. 但它不会对Web视图的字体大小进行任何更改。
I suggest you add CSS
code to the content. 我建议您将
CSS
代码添加到内容中。
I had to do this one time, and here's an example from my code: 我不得不做一次,这是我的代码中的一个示例:
NSString *systemFont = [[[UIFont systemFontOfSize:11.f] description] fontCSS];
NSString *boldFont = [[[UIFont boldSystemFontOfSize:12.f] description] fontCSS];
// The above fonts can be changed to your liking.
NSString *oldContent = ___; // This is the html content that was loaded.
NSString *content = [NSString stringWithFormat:@"<html><head>\
<style>\
img,iframe{max-width:100%%; width:auto; height:auto; display:block; margin-left:auto; margin-right:auto; margin-bottom:20px}\
body{%@; margin-left:24px; margin-right:24px; margin-bottom:24px}\
strong{%@}\
</style>\
</head><body>%@</body></html>", systemFont, boldFont, oldContent];
Now you use the content
variable with your webview
. 现在,您可以在
webview
使用content
变量。
The fontCSS
method is as follows, it's in an NSString category: fontCSS
方法如下所示,它位于NSString类别中:
-(NSString *)fontCSS
{
NSRange range = [self rangeOfString:@"font-family"];
return [self substringFromIndex:range.location];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.