mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
15 lines
656 B
Swift
15 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)
|
|
}
|
|
}
|