diff --git a/Tusker/Views/Profile Header/ProfileFieldValueView.swift b/Tusker/Views/Profile Header/ProfileFieldValueView.swift index beeba3297..0d379b602 100644 --- a/Tusker/Views/Profile Header/ProfileFieldValueView.swift +++ b/Tusker/Views/Profile Header/ProfileFieldValueView.swift @@ -39,24 +39,24 @@ class ProfileFieldValueView: UIView { let converted = NSMutableAttributedString(attributedString: ProfileFieldValueView.converter.convert(field.value)) - var range = NSRange(location: 0, length: 0) - if converted.length != 0, - let url = converted.attribute(.link, at: 0, longestEffectiveRange: &range, in: converted.fullRange) as? URL { - link = (converted.attributedSubstring(from: range).string, url) + converted.enumerateAttribute(.link, in: converted.fullRange) { value, range, stop in + guard value != nil else { return } + if self.link == nil { + self.link = (converted.attributedSubstring(from: range).string, value as! URL) + } + #if os(visionOS) + converted.addAttribute(.foregroundColor, value: UIColor.link, range: range) + #else + converted.addAttribute(.foregroundColor, value: UIColor.tintColor, range: range) + #endif + // the .link attribute in a UILabel always makes the color blue >.> + converted.removeAttribute(.link, range: range) + } + + if link != nil { label.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(linkTapped))) label.addInteraction(UIContextMenuInteraction(delegate: self)) label.isUserInteractionEnabled = true - - converted.enumerateAttribute(.link, in: converted.fullRange) { value, range, stop in - guard value != nil else { return } - #if os(visionOS) - converted.addAttribute(.foregroundColor, value: UIColor.link, range: range) - #else - converted.addAttribute(.foregroundColor, value: UIColor.tintColor, range: range) - #endif - // the .link attribute in a UILabel always makes the color blue >.> - converted.removeAttribute(.link, range: range) - } } label.numberOfLines = 0