是否可以在UIWebview ios中更改文本选择颜色? [英] Is it possible to change text selection color in UIWebview ios?

查看:177
本文介绍了是否可以在UIWebview ios中更改文本选择颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UIwebview中加载了html文件,并将以下代码放在html文件中。

I have load html file in UIwebview and had put below code in html file.

 <style>
  ::-moz-selection { /* Code for Firefox */
              color: red;
              background: yellow;
          }

      ::selection {
          color: red;
          background: yellow;
      }
      </style>

并且在Uiwebview中设置了颜色,但是当我选择文本时,它仍然显示蓝色。 / p>

and also set tint color in Uiwebview but still it is showing blue color when i am selecting text.

推荐答案

是的。我浪费了 2 天来解决此头痛问题。请访问此链接,将JS代码放在JS中File.Import in .HTML file。

Yes. I wasted 2 days to resolve this headache issue.Visit This Link and Place JS Code in your JS File.Import it in .HTML file.

下面是它的示例代码。

function highlight(colour) {
var range, sel;
if (window.getSelection) {
    // IE9 and non-IE
    try {
        if (!document.execCommand("BackColor", false, colour)) {
            makeEditableAndHighlight(colour);
        }
    } catch (ex) {
        makeEditableAndHighlight(colour)
    }
} else if (document.selection && document.selection.createRange) {
    // IE <= 8 case
    range = document.selection.createRange();
    range.execCommand("BackColor", false, colour);
}}

通过Objective-C代码调用此方法

call this method by Objective-C code

[webView stringByEvaluatingJavaScriptFromString:@"highlight('#ff0')"];

这篇关于是否可以在UIWebview ios中更改文本选择颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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