session-ios/Signal/src/Loki/Utilities/UILabel+Interaction.swift
Niels Andriesse 495c19452e Include EULA
2020-02-06 13:31:07 +11:00

16 lines
656 B
Swift

extension UILabel {
func characterIndex(for point: CGPoint) -> Int {
let textStorage = NSTextStorage(attributedString: attributedText!)
let layoutManager = NSLayoutManager()
textStorage.addLayoutManager(layoutManager)
let textContainer = NSTextContainer(size: bounds.size)
textContainer.lineFragmentPadding = 0
textContainer.maximumNumberOfLines = numberOfLines
textContainer.lineBreakMode = lineBreakMode
layoutManager.addTextContainer(textContainer)
return layoutManager.characterIndex(for: point, in: textContainer, fractionOfDistanceBetweenInsertionPoints: nil)
}
}