5

How can I detect if the user pasted something into a UITextField?

All answers I'm finding online and on StackOverflow pertain to UITextViews.

user86516512
  • 445
  • 4
  • 13
  • 3
    This [answer](https://stackoverflow.com/a/45960062/5078779) is for UITextField even though the question asks about UITextView. – Daniel Aug 22 '20 at 22:38

1 Answers1

7

You just need to override UIResponderStandardEditActions paste method on your UITextField delegate:

override func paste(_ sender: Any?) {
    print("do someting")
    super.paste(sender)
}
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
  • how can i get access to the text in the clipboard/paste buffer? – frlzjosh Sep 29 '22 at 21:37
  • I found out I can get access to that through `UIPasteboard.general.string` – frlzjosh Sep 29 '22 at 21:51
  • 1
    @frlzjosh make sure to check if the pasteboard `hasString` before trying to access it [How to check if there is something on the clipboard](https://stackoverflow.com/a/48134316/2303865) – Leo Dabus Sep 30 '22 at 00:25