![](/img/trans.png)
[英]WKWebView contentSize height not changing after resize font size
[英]how to resize the wkwebview font size?
无论iOS编程中的Webkit内容如何,如何更改WKWebView
的字体大小?
我正在使用[Webview stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"resizeText(%lu)",(unsigned long)fontSize]];
但它不会对Web视图的字体大小进行任何更改。
我建议您将CSS
代码添加到内容中。
我不得不做一次,这是我的代码中的一个示例:
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];
现在,您可以在webview
使用content
变量。
fontCSS
方法如下所示,它位于NSString类别中:
-(NSString *)fontCSS
{
NSRange range = [self rangeOfString:@"font-family"];
return [self substringFromIndex:range.location];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.