UITextView提供了一个非常有用的数据检测器功能,它支持:
我准备了一个小样本来测试它,我只有一个问题:
如何更改检测到的文本的外观?
应用于tintColor和/或linkTextAttributes的更改似乎只适用于URL、电子邮件和电话号码。应用于tintColor或linkTextAttributes属性UITextView的更改似乎不会对事件/日期或时间、地址、托运号和航班号等项目产生任何影响。

发布于 2016-12-14 09:47:49
使用NSDataDetector似乎只有一种方式。
数据检测的样本如下。
let wAS = aTextView.attributedText.mutableCopy() as! NSMutableAttributedString
let wDateResult = try! NSDataDetector( types: NSTextCheckingResult.CheckingType.date.rawValue ).matches(
in: wAS.string
, options: NSRegularExpression.MatchingOptions( rawValue: 0 )
, range: NSMakeRange( 0, wAS.string.characters.count )
)
for w in wDateResult {
wAS.addAttributes( [ NSForegroundColorAttributeName : UIColor.red ], range: w.range )
}
aTextView.attributedText = wAShttps://stackoverflow.com/questions/41136834
复制相似问题