[英]I want the text to be deleted when I tap on textfield
I'm making an easy app where I have textFields. 我正在制作一个具有textFields的简单应用程序。 When the app starts I have examples in my textfields.
应用启动时,我的文本字段中有示例。 I want these text examples to be deleted when users tap on textField.
我希望这些文本示例在用户点击textField时被删除。 Can anybody help me?
有谁能够帮助我?
You can set Placeholder text in UITextField . 您可以在UITextField中设置占位符文本。 Whenever, UITextField is tapped placeholder text disappears.
每当UITextField被点击时,占位符文本就会消失。
Alternatively, you can use following UITextFieldDelegate method 或者,您可以使用以下UITextFieldDelegate方法
Objective-C Objective-C的
- (void)textFieldDidBeginEditing:(UITextField *)textField {
textField.text = ""
}
Swift 迅速
func textFieldDidBeginEditing(textField: UITextField) {
textField.text = ""
}
Just add this underneath your didMoveToView method in youre SpriteKit Game 只需在您的SpriteKit游戏中的didMoveToView方法下面添加此代码
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()
}
}
}
I think you are trying to create text field with placeholder. 我认为您正在尝试使用占位符创建文本字段。
this link might helps you. 此链接可能会对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.