'UILabel NSAttributedString.link not clickable when contains Unicode string
when using normal text (English) it is work normal I can click able on link
here is code
let attText = NSMutableAttributedString(string: text, attributes: [NSAttributedString.Key.font : UIFont(name: "Lato-Regular", size: 15)!])
let detector = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
let matches = detector.matches(in: text, options: [], range: NSRange(location: 0, length: text.utf16.count))
for match in matches {
guard let range = Range(match.range, in: text) else { continue }
let url = text[range]
if let validURL = URL(string: String(url)) {
if UIApplication.shared.canOpenURL(validURL) {
attText.addAttributes([.link : URL(string: String(url))!], range: match.range)
}
}
}
let label = UILabel()
label.isUserInteractionEnabled = true
label.lineBreakMode = .byWordWrapping
label.numberOfLines = 0
label.preferredMaxLayoutWidth = width
label.attributedText = attText
return label
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

