2

我在里面看到了一些奇怪的东西UITextView。能够检测到我的UITextView地址,但我无法设置文本样式,即使我能够设置电话号码和网络链接的样式。

请参阅下面的代码(我已经尝试过tintColor& linkTextAttributes- 两者似乎都适用于地址链接以外的东西)

let t = "One Infinite Loop Cupertino, CA 95014 some other text yeah www.google.com 123-555-1212 One Infinite Loop Cupertino, CA 95014"
let a = NSAttributedString(string: t)

self.textView.attributedText = a
self.textView.isEditable = false

self.textView.textColor = .green
self.textView.tintColor = .blue

self.textView.dataDetectorTypes = [.link, .address, .phoneNumber]

let linkAttributes: [String : Any] = [
    NSAttributedStringKey.foregroundColor.rawValue: UIColor.red,
    NSAttributedStringKey.underlineColor.rawValue: UIColor.orange,
    NSAttributedStringKey.underlineStyle.rawValue: NSUnderlineStyle.styleSingle.rawValue]

self.textView.linkTextAttributes = linkAttributes

在此处输入图像描述

如您所见,地址带有下划线且可单击(单击会将我带到地图),但红色并未应用于它,即使数据检测器检测到的其他内容已被拾取。

想法?

4

0 回答 0