如何在 UITextview 中使用 linkTextAttributes swift
How to use linkTextAttributes in UITextview swift
当我收到来自服务器响应的链接时,我正在更改超链接颜色。但它也会影响字母数字。我不想更改数字项的超链接颜色。就我而言,我从响应中收到帐号,文本颜色更改为超链接颜色。
例如:
2344-323-3242
(23432-3423-324)
/n 23234-324-234-234
subtitleTextView.linkTextAttributes = [NSAttributedStringKey.foregroundColor.rawValue: ThemeColor.textHyperLinkColor.value, NSAttributedStringKey.underlineStyle.rawValue: NSUnderlineStyle.styleNone.rawValue]
最简单的方法就是禁用 phone 号码检测。从代码中你需要添加你需要的所有检测器 - 如果你需要除 phone 数字之外的所有检测器,代码将是:
subtitleTextView.dataDetectorTypes = UIDataDetectorTypes(rawValue:
UIDataDetectorTypes.link.rawValue +
UIDataDetectorTypes.address.rawValue +
UIDataDetectorTypes.calendarEvent.rawValue +
UIDataDetectorTypes.shipmentTrackingNumber.rawValue +
UIDataDetectorTypes.flightNumber.rawValue +
UIDataDetectorTypes.lookupSuggestion.rawValue)
当我收到来自服务器响应的链接时,我正在更改超链接颜色。但它也会影响字母数字。我不想更改数字项的超链接颜色。就我而言,我从响应中收到帐号,文本颜色更改为超链接颜色。
例如:
2344-323-3242
(23432-3423-324)
/n 23234-324-234-234
subtitleTextView.linkTextAttributes = [NSAttributedStringKey.foregroundColor.rawValue: ThemeColor.textHyperLinkColor.value, NSAttributedStringKey.underlineStyle.rawValue: NSUnderlineStyle.styleNone.rawValue]
最简单的方法就是禁用 phone 号码检测。从代码中你需要添加你需要的所有检测器 - 如果你需要除 phone 数字之外的所有检测器,代码将是:
subtitleTextView.dataDetectorTypes = UIDataDetectorTypes(rawValue:
UIDataDetectorTypes.link.rawValue +
UIDataDetectorTypes.address.rawValue +
UIDataDetectorTypes.calendarEvent.rawValue +
UIDataDetectorTypes.shipmentTrackingNumber.rawValue +
UIDataDetectorTypes.flightNumber.rawValue +
UIDataDetectorTypes.lookupSuggestion.rawValue)