From b3cc938a9e4504ad3a5dd9af81f7f39e2592f602 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 20 Sep 2019 16:11:46 -0400 Subject: [PATCH] Improved accuracy of link label detection. --- MVMCoreUI/Atoms/Views/Label.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index aa677cd1..e1c4cc5e 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -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) } }