【问题标题】:UIWebView magically underlines some kind of textUIWebView 神奇地强调了某种文本
【发布时间】:2019-02-21 09:03:07
【问题描述】:

如果 "Card.io" 写在 html 字符串中,UIWebview 会在下面的字符串中将其显示为带下划线的文本。

<p>
    <strong>Card.io</strong>
    <br />The MIT License (MIT)<br />
    Copyright (c) 2013-2016 PayPal Holdings, Inc.<br />
    Permission is hereby granted, ...<br />
    The above copyright notice ...<br />
    THE SOFTWARE IS PROVIDED "AS IS" ... <br />...
    ......
</p>

如果写的是“Hello World”而不是“Card.io”,UIWebview 会将其显示为粗体,但没有像预期的那样加下划线。

<p>
    <strong>Hello World</strong>
    <br />The MIT License (MIT)<br />
    Copyright (c) 2013-2016 PayPal Holdings, Inc.<br />
    Permission is hereby granted, ...<br />
    The above copyright notice ...<br />
    THE SOFTWARE IS PROVIDED "AS IS" ... <br />...
    ......
</p>

为什么 UIWebView 将“Card.io”显示为带下划线的字符串?有什么想法吗?

【问题讨论】:

    标签: ios uiwebview


    【解决方案1】:

    对于此问题,未选中 UIWebView 的“Link”属性。

    现在您将获得预期的输出作为您的要求。

    【讨论】:

    • 也未选中“电话号码”属性以删除 2013-2016 年的下划线
    • 感谢“电话号码”的建议。
    【解决方案2】:

    “Card.io”是一个URL,所以会被直接检测到。

    如果您不想检测 URL/链接,请设置 UIDataDetectorTypes

    webView.dataDetectorTypes.remove(.link)
    

    Swift 版本:4.x

    在 iOS 8 及更高版本中运行的应用程序中,使用 WKWebView 类而不是 UIWebView。

    let theConfiguration : WKWebViewConfiguration = WKWebViewConfiguration()
    theConfiguration.dataDetectorTypes.remove(.link)
    let wkWebView = WKWebView(frame: CGRect(x: 0, y: 0, width: 10, height: 10), configuration: theConfiguration)
    

    您也可以通过 Inspectors 进行此更改

    【讨论】:

      【解决方案3】:

      为了从 WKWebView 中的选定链接中删除蓝色链接,请在“a href”标记之前添加此 HTML 标记:

      &lt;STYLE&gt;A {text-decoration: none;} &lt;/STYLE&gt;

      所以在 WKWebView 中加载的 html 可能是:

      <STYLE>A {text-decoration: none;} </STYLE>
      <a href=\"https://www.stackoverflow.com\">
      <div>This might be some text that you do not want a blue underline</div>
      </a>

      我确实尝试在 div 标签中添加样式,但是蓝色下划线仍然存在。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-07-31
        • 2021-10-21
        • 2022-07-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-22
        相关资源
        最近更新 更多