Although there is no public API to do this, I was curious and decided to dig through the private header for UITextField
. I found that there is a class method on UITextField
_sharedHighlightView
which returns an instance of the private _UIHighlightView
class. This is the class in charge of the highlighting. Swizzling _sharedHighlightView
and changing its color will allow you to change the color of any data-detected links:
WARNING: This is a hack that uses method swizzling and private APIs/properties.
class MyTextView: UITextView {
var newHighlightView: AnyObject?
func changeHighlight() {
self.newHighlightView = UITextView.performSelector(Selector("_sharedHighlightView")).takeUnretainedValue()
self.newHighlightView?.setValue(UIColor.redColor().colorWithAlphaComponent(0.6), forKey: "_color")
let originalHighlightView = class_getClassMethod(MyTextView.self, Selector("_sharedHighlightView"))
let newHighlightView = class_getClassMethod(MyTextView.self, #selector(MyTextView.swizzleHighlightView))
method_exchangeImplementations(originalHighlightView, newHighlightView)
}
func swizzleHighlightView() -> AnyObject {
return self.newHighlightView!
}
}
In your View Controller:
let textView = MyTextView(frame: CGRect(x: 0, y: 40.0, width: 200.0, height: 200.0))
textView.dataDetectorTypes = .All
textView.editable = false
textView.text = "Some text. http://www.google.com/"
textView.changeHighlight()
self.view.addSubview(textView)
Result:

This could probably be cleaned up a little further by not force-unwrapping any optionals.