Because the WebView property is not changing the font size color of these requirements, only by changing the CSS style, built-in to solve. Baidu on the search for a long time a lot of not reliable, now gives several solutions as follows:
1. The first way: In the WebView proxy method Webviewdidfinishload:
Font size: [WebView stringbyevaluatingjavascriptfromstring:@ "document.getelementsbytagname (' body ') [0]. style.webkittextsizeadjust= ' 12% ' "];
Font color:[WebView stringbyevaluatingjavascriptfromstring:@ "document.getelementsbytagname (' body ') [0]. Style.webkittextfillcolor= ' green ' "];
Background color:[WebView stringbyevaluatingjavascriptfromstring:@ "document.getelementsbytagname (' body ') [0]. style.background= ' #F6F7F3 ' "];
2. The first way: in the following can change the margin size to change the WebView text distance margin size, 13 represents the fontsize, self. Strbooktips is the string to be manipulated.
nsstring *bookstr = [nsstringstringwithformat:@ "
"
"<style type=\" text/css\ "> \ n"
"Body {margin:10;font-size:%d;} \ n "
"</style> \ n"
"
"<body>%@</body> \ n"
",self. Strbooktips];
[Self. WebView loadhtmlstring: Bookstr baseURL:nil];
3. The third way, this lack of changing the background color
nsstring * formatString =@ "<span style=\" Font-size:13px;color: #7E7C8A \ ">%@</ Span> ";
nsstring * htmlstring = [nsstring stringwithformat : Formatstring,self . strbooktips ];
[ self webview &NBSP; loadhtmlstring :BOOKSTR&NBSP; baseurl : nil ";
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Change webview font size, color, background color by setting CSS in iOS