0

When I click on a UILabel, I want to get the character of the clicked position, but UILabel has no API,what should I do?

summer
  • 11
  • 1
  • The trick is, the UILabel has multiple lines, and the text is really attributedText, so it's a bit tough to find the exact character at the click position of the – summer May 07 '20 at 14:43
  • The linked answer is originally for UITextView, but explains how to deal with UILabel as well. The key tool is NSLayoutManager.characterIndexForPoint. – Rob Napier May 07 '20 at 14:44
  • See also https://stackoverflow.com/questions/42240683/how-do-i-detect-and-make-clickable-links-in-a-uilabel-not-using-uitextview/42240972, which includes Swift code and more discussion of the necessary techniques. – Rob Napier May 07 '20 at 14:47

0 Answers0