【问题标题】:Can't set color of URL in webview无法在 webview 中设置 URL 的颜色
【发布时间】:2015-10-16 15:45:54
【问题描述】:

我目前正在努力解决一个简单的问题:我试图在我的 webview 中设置链接颜色,但它没有效果:

[self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='padding: 0px 20px; font-size:16px;font-family:HelveticaNeue-Light; a:link {text-decoration:none; color:#009fe3; } a:visited { text-decoration:none; color:#009fe3;}; color:#fff;>%@<div>",urlString] baseURL:nil];

我的代码有什么问题?

【问题讨论】:

  • 你有没有试过在外面运行html代码,看看它是否有效?尝试加载 html 文件而不是加载纯字符串
  • 尝试在 JavaScript 中更改 URL 颜色,并像 ` [webView stringByEvaluatingJavaScriptFromString:@"script"]` 一样应用它

标签: html objective-c uiwebview


【解决方案1】:

幸运的是,链接颜色最初是在我的 HTML 字符串中设置的唯一颜色,所以我最终覆盖了十六进制颜色代码:

NSString *copy = [urlString stringByReplacingOccurrencesOfString:@"#2E2EFE"withString:@"#009fe3"];
[self.webView loadHTMLString:copy baseURL:nil];

这可能是一种解决方法,但它确实有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多