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?
Asked
Active
Viewed 2,142 times
4
-
2Instead of setting the `text` property of these fields you should simply set the `placeholder` property. – Rok Jarc May 24 '16 at 17:09
3 Answers
4
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 = ""
}

Ashish Verma
- 1,776
- 1
- 16
- 27
-
1
-
There is only one problem here: any text would be cleared in your case (when using the `text` instead of the `placeholder` property) as soon as user begins editing. One should at least compare the content to 'initial' content and clear if (and only if) they are a match. – Rok Jarc May 24 '16 at 18:02
-
1It's not clear from question what exactly @lucca910 wants to acheive. Whether he wants to delete text every time like in some cases of Passwords. – Ashish Verma May 24 '16 at 18:16
1
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()
}
}
}
0
I think you are trying to create text field with placeholder.
this link might helps you.

Community
- 1
- 1

Anilkumar Amrutham
- 11
- 3
-
2Why are you linking to a question about putting a placeholder in a `UITextView`? This question is about `UITextField`. – rmaddy May 24 '16 at 17:18