简体   繁体   English

我想在点击文本框时删除文本

[英]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. 此链接可能会对您有所帮助。

Placeholder in UITextView UITextView中的占位符

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么当我点击文本字段时工具栏不显示? - Why is the toolbar not showing when I tap on the textfield? 我想快速编辑结束时(当用户转到下一个字段时)将文本字段文本转换为安全文本,例如密码 - I want to convert textfield text into secure text like password when editing end(when user goes to next field) in swift 卸载应用程序时,我不希望删除 SqlLite 数据库 - When uninstall the application, I don't want the SqlLite database to be deleted 在Appium中,我试图使用xpath访问(单击按钮或在文本字段中编辑文本)webview中的元素。 但是我做不到 - In Appium, I am trying to access(tap a button or edit text in textfield) elements in webview using xpath. But i can't able to do 为什么在我点击按钮时,它们的文字颜色没有改变? - Why is the text color of my buttons not changing when I tap on them? 点击时自动选择文本字段中的文本 - Auto selection of text in textfield on tap 当我在特定位置点击UITextView时,我想更改该特定行的颜色 - When I tap on UITextView at a particular place I want to change the color of that particular line 每次我重新点击文本字段时,视图都会发生变化 - View is getting shifted every time I re-tap textfield 当这个 textField 在 Swift 中被禁用时,点击 textField 的 rightView? - Tap on rightView of textField when this textField be disabled in Swift? 当我在textField中键入任何内容时,我想在导航栏上显示按钮 - when i am typying anything in textField, I want to show button on navigationbar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM