vds_ios/VDS/Extensions/UITapGestureRecognizer.swift
Matt Bruce 8a5b828a84 udpated method name
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-04-17 13:24:04 -05:00

30 lines
1.0 KiB
Swift

//
// UITapGesture.swift
// VDS
//
// Created by Matt Bruce on 8/4/22.
//
import Foundation
import UIKit
extension UITapGestureRecognizer {
public func didTapActionInLabel(_ label: UILabel, inRange targetRange: NSRange) -> Bool {
guard let attributedText = label.attributedText else { return false }
let layoutManager = NSLayoutManager()
let textContainer = NSTextContainer(size: label.bounds.size)
let textStorage = NSTextStorage(attributedString: attributedText)
layoutManager.addTextContainer(textContainer)
textStorage.addLayoutManager(layoutManager)
let location = location(in: label)
let characterIndex = layoutManager.characterIndex(for: location, in: textContainer, fractionOfDistanceBetweenInsertionPoints: nil)
guard let _ = attributedText.attribute(NSAttributedString.Key.action, at: characterIndex, effectiveRange: nil) as? String, characterIndex < attributedText.length else { return false }
return true
}
}