2017-08-01 16 views
9

Tôi đang cố gắng thay đổi màu lựa chọn văn bản trong WKWebView. Tôi đã thử khá nhiều giải pháp được đề xuất cho UIWebView/WKWebView mà tôi có thể tìm thấy.Làm thế nào để thay đổi màu lựa chọn văn bản trong WKWebView?

Thay đổi tông màu không hoạt động. Áp dụng css cho các thẻ ::selection, -webkit-tap-highlight-color không hoạt động.

enter image description here

Luôn xanh. Liệu có thể thay đổi nó không?

+0

có thể điều này sẽ giúp bạn .. https://stackoverflow.com/questions/28642485/is-it-possible-to-change -text-selection-color-in-uiwebview-ios –

Trả lời

1

Đây là mã mẫu cho nó.

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); 
}} 

gọi phương pháp này bởi mã Objective-C

[webView stringByEvaluatingJavaScriptFromString:@"highlight('#ff0')"]; 
Các vấn đề liên quan