Improved accuracy of link label detection.
This commit is contained in:
parent
efbb68b4cd
commit
b3cc938a9e
@ -689,7 +689,7 @@ extension UITapGestureRecognizer {
|
||||
paragraph.alignment = label.textAlignment
|
||||
|
||||
let stagedAttributedString = NSMutableAttributedString(attributedString: attributedText)
|
||||
stagedAttributedString.addAttributes([NSAttributedString.Key.paragraphStyle: paragraph], range: NSRange(location: 0, length: attributedText.string.count))
|
||||
stagedAttributedString.addAttributes([NSAttributedString.Key.paragraphStyle: paragraph], range: NSRange(location: 0, length: attributedText.string.count))
|
||||
|
||||
let textStorage = NSTextStorage(attributedString: stagedAttributedString)
|
||||
let layoutManager = NSLayoutManager()
|
||||
@ -704,8 +704,8 @@ extension UITapGestureRecognizer {
|
||||
textContainer.size = label.bounds.size
|
||||
|
||||
let indexOfGlyph = layoutManager.glyphIndex(for: location(in: label), in: textContainer)
|
||||
|
||||
return NSLocationInRange(indexOfGlyph, targetRange)
|
||||
|
||||
return layoutManager.boundingRect(forGlyphRange: targetRange, in: textContainer).contains(location(in: label)) && NSLocationInRange(indexOfGlyph, targetRange)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user