清除UITextField占位符文本

清除UITextField占位符文本

本文介绍了清除UITextField占位符文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xcode4中,我为UITextField创建了一些占位符文本,我希望它能清除用户点击框中的内容。

In Xcode4 I've created some placeholder text for a UITextField and I'd like it to clear when the user taps in the box.

所以,在属性文本字段的检查器我点击了编辑开始时清除但是当我点击文本框时它不会立即删除文本(它只在您开始输入时消失)。

So, in the Attributes Inspector for the text field I've clicked "Clear when editing begins" however this does not immediately remove the text when I tap in the text box (it only disappears when you start typing).

有没有办法在点击文本框时立即删除占位符文本?

Is there any way of removing the placeholder text immediately on tapping in the text box?

推荐答案

使您的ViewController成为textField的委托并实现这两种方法:

make your ViewController the delegate of the textField and implement those two methods:

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    textField.placeholder = nil;
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    textField.placeholder = @"Your Placeholdertext";
}

这篇关于清除UITextField占位符文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 02:28