あなたがTextViewの上ご起因する文字列を設定した後、次の操作を行います
//Change UIFont to your font and size
if let attributedString = textView.attributedText, let font = UIFont(name: "YourFontName", size: 14) {
let newString = NSMutableAttributedString(attributedString: attributedString)
let types: NSTextCheckingResult.CheckingType = [.link, .phoneNumber, .address, .date, .transitInformation]
let linkDetector = try? NSDataDetector(types: types.rawValue)
let range = NSRange(location:0,length: attributedString.length)
linkDetector?.enumerateMatches(in: attributedString.string, options: [], range: range, using: {
(match : NSTextCheckingResult?, flags : NSRegularExpression.MatchingFlags, stop) in
if let matchRange = match?.range {
newString.removeAttribute(NSFontAttributeName, range: matchRange)
newString.addAttribute(NSFontAttributeName, value: font, range: matchRange)
}
})
textView.attributedText = newString
}