How to define link text color in UIWebView

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 12:44:13

问题


I have a short plain text string, which might contain a weblink. I load it into UIWebView using loadHTMLString and notice that e.g. font style and size are wrong. Can't find anything else, so I embed text inside ad hoc HTML document with CSS (is this REALLY the only way):

NSString *myHtml = [NSString stringWithFormat:
                    @"<html><head>"
                    "<style type=\"text/css\">"
                    "body{"
                    "font-family: Helvetica;"
                    "font-size: 20px;"
                    "a {color: #FFF;}"
                    "},</style>"
                    "</head><body>%@</body></html>", myText];
[self.myWebView loadHTMLString:myHtml baseURL:nil];    

Problem: Just can't figure out how to change link style. Tried a {color:#fff;}, *:link{color:#fff;} etc. which don't even recall anymore. Nothing changed anything about default link look and feel! Not color, not size, not background, nothing!

Any tips how to have any control whatsoever about how links look like? Would using javaScript be the only possibility?


回答1:


You nested the a rule inside the body rule. Move it outside.



来源:https://stackoverflow.com/questions/2205964/how-to-define-link-text-color-in-uiwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!