lucca910
lucca910

Reputation: 111

I want the text to be deleted when I tap on textfield

I'm making an easy app where I have textFields. When the app starts I have examples in my textfields. I want these text examples to be deleted when users tap on textField. Can anybody help me?

Upvotes: 4

Views: 2250

Answers (3)

Ashish Verma
Ashish Verma

Reputation: 1818

You can set Placeholder text in UITextField. Whenever, UITextField is tapped placeholder text disappears.

Alternatively, you can use following UITextFieldDelegate method

Objective-C

 - (void)textFieldDidBeginEditing:(UITextField *)textField {
   textField.text = ""
}

Swift

func textFieldDidBeginEditing(textField: UITextField) {
  textField.text = ""
}

Upvotes: 4

user4410715
user4410715

Reputation:

Just add this underneath your didMoveToView method in youre SpriteKit Game

override func touchesBegan(touches: Set<UITouch>, with Event event: UIEvent?) {

for touch in touches {
    let location = touch.locationInNode(self)
       if nodeAtPoint(location) = textField {
          textField.removeFromParent()
            }
       }
     }

Upvotes: 1

Anilkumar Amrutham
Anilkumar Amrutham

Reputation: 11

I think you are trying to create text field with placeholder.

this link might helps you.

Placeholder in UITextView

Upvotes: 0

Related Questions