How to change colour of dataDetectorType link in UIWebView?

1.7k views Asked by At

I want to change all dataDetectorType Colour in UIWebView including PhoneNo , emailID , Calendar and every dataDetctorType. I also need Tappable link for that dataDetector link.

3

There are 3 answers

0
Thomas Deniau On

For UITextView, you can use linkTextAttributes for this, but there is no such thing for UIWebView. You will have to add CSS to the content you are loading to style the automatically inserted A tags.

0
Yun CHEN On

CSS example to change the detected link color:

NSString *html = @"<style>a:link { color: red; }</style> <h3>detected phone number: 111122223333</h3> <a href='www.google.com'>google link</a>";
[webView loadHTMLString:html baseURL:nil];

The result in WebView:
enter image description here

1
zath On

Adding some CSS to set the link color works, but for auto-detected links and e-mails etc it is necessary to add !important for the color to be applied.

<style>a { color: red !important; }</style>