如何在UIWebView中定义链接文本颜色 [英] How to define link text color in UIWebView

查看:30
本文介绍了如何在UIWebView中定义链接文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简短的纯文本字符串,其中可能包含网络链接.我使用loadHTMLString将其加载到UIWebView中,并注意到例如字体样式和大小错误.找不到其他东西,所以我将文本与CSS一起嵌入到临时HTML文档中(这确实是唯一的方法):

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

问题:只是无法弄清楚如何更改链接样式.尝试了{color:#fff;},*:link {color:#fff;}等,它们甚至都不记得了.默认链接外观没有任何改变!没有颜色,没有大小,没有背景,什么都没有!

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!

任何技巧如何控制链接的外观?使用javaScript是唯一的可能性吗?

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

推荐答案

您将 a 规则嵌套在 body 规则内.将其移到外面.

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

这篇关于如何在UIWebView中定义链接文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆