简体   繁体   English

如何更改颜色和字体大小UIWebview

[英]How to change the color and font size UIWebview

In my application I am loading HTML String which is parsed from the json file the string already contain font color and font size but I need to change the color and size of the font. 在我的应用程序中,我正在加载从json文件解析的HTML字符串,该字符串已经包含字体颜色和字体大小,但是我需要更改字体的颜色和大小。 To replace that I have already use the followings code but its not working 要替换它,我已经使用了以下代码,但无法正常工作

NSString *webString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%d%%'", 
                          textFontSize];
    [web stringByEvaluatingJavaScriptFromString:webString];

Is there is any other way to change it.If yes means please suggest me the answer. 还有其他方法可以更改它。如果是,请给我建议答案。

try this, 尝试这个,

[webView  loadHTMLString:[NSString stringWithFormat:@"<div id ='foo' align='justify' style='font-size:14px; font-family:helvetica; color:#ffffff';>%@<div>",yourString] baseURL:nil];

it may helps you.... 它可能会帮助您。

You can try this java script in to your webview's delegate webViewDidFinishLoad method 您可以尝试将此Java脚本放入webViewDidFinishLoad的委托webViewDidFinishLoad方法中

NSString *setTextSizeRule = [NSString stringWithFormat:@"addCSSRule('body', '-webkit-text-size-adjust: %d%%;')", currentTextSize];

NSString *changeColor = [NSString stringWithFormat:@"addCSSRule('html, body, div, p, span, a', 'color: #000000;')"];

[webView stringByEvaluatingJavaScriptFromString:setTextSizeRule];
[webView stringByEvaluatingJavaScriptFromString:changeColor];

You can do so many changes using java script in webview's did finish load method. 您可以在webview的did finish加载方法中使用Java脚本进行许多更改。

Let me know if you still able to not solve 让我知道您是否仍然无法解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM