4

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. 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.

4

2 回答 2

5

尝试这个,

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

它可能会帮助你....

于 2012-11-03T08:57:39.923 回答
1

您可以在 webview 的委托webViewDidFinishLoad方法中尝试这个 java 脚本

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];

您可以在 webview 的 done 加载方法中使用 java 脚本进行很多更改。

如果您仍然无法解决,请告诉我

于 2014-05-01T06:01:52.207 回答