1.第一种方式:在WebView的代理方法webViewDidFinishLoad中:
字体大小: [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName(‘body‘)[0].style.webkitTextSizeAdjust= ‘12%‘"];
字体颜色:[webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName(‘body‘)[0].style.webkitTextFillColor= ‘green‘"];
背景颜色:[webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName(‘body‘)[0].style.background=‘#F6F7F3‘"];
2.第一种方式:在下面可以通过改变margin大小来改变webview文字距离边距大小,13代表字体大小,self.strBookTips是要被操作的字符串。
NSString *BookStr = [NSString stringWithFormat:@"<html> \n"
"<head> \n"
"<style type=\"text/css\"> \n"
"body {margin:10;font-size: %d;}\n"
"</style> \n"
"</head> \n"
"<body>%@</body> \n"
"</html>",13,self.strBookTips];
[self.webView loadHTMLString:BookStr baseURL:nil];
3.第三种方式,这种缺少了改变背景颜色
NSString * formatString = @"<span style=\"font-size:13px;color:#7E7C8A\">%@</span>";
NSString * htmlString = [NSString stringWithFormat:formatString,self.strBookTips];
[self.webView loadHTMLString:BookStr baseURL:nil];
来源:CSDN
作者:jack_yuh
链接:https://blog.csdn.net/yuhao111122/article/details/50560876