1

的UITextView提供了一個非常有用的數據檢測功能,支持:的UITextView的數據檢測選項和文本外觀

  • 電話號碼檢測
  • URL檢測街道地址檢測
  • 事件檢測
  • 出貨追蹤號碼檢測
  • 航班號檢測和
  • 信息的用戶可能想看看高達

我準備了一個小樣本來測試它,我只是有一個問題:

我怎樣才能改變檢測文本的外觀?

適用於tintColor和/或linkTextAttributes的更改似乎只適用於網址,電子郵件和電話號碼。應用的UITextView的tintColorlinkTextAttributes性質的變化似乎並沒有對類似事件/日期或時間,地址,裝運編號,以及航班號項目的任何影響。

UITextView's Data Detectors option sample

+0

您應該在bugreport.apple.com上提供一個關於此問題的bug。如果linkTextAttributes不適用於iOS 10中新的「輕量級」鏈接,那麼應該可以自定義它們。 –

+0

提交的問題。參考#29660476. – Mustafa

+0

@Mustafa在那裏你能解決這個問題? – unniverzal

回答

0

似乎只有一個使用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 = wAS