-1

I want to know how to reset the value entered in the textfield by pressing the button.

When I was doing java, I remembered that it was possible with just one command line, but I was wondering if there was such a way for Swift, so I ask a question.

ex) If you click the reset button after entering the value hi in the text field, the value hi is cleared.

je2
  • 35
  • 1
  • 6

2 Answers2

4

you could simply do this inside your IBAction func

yourTextFieldOutlet.text = ""
sushitrash
  • 174
  • 1
  • 8
3

There's a built-in clear button that you can enable like this:

textField.clearButtonMode = .whileEditing

This adds a clear button while the user is editing your text field.

Alternatively, you can just set the text to "" as @Arya Surya said.

aheze
  • 24,434
  • 8
  • 68
  • 125