![](/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.