添加“清除”按钮到iPhone UITextField [英] Adding the "Clear" Button to an iPhone UITextField
问题描述
如何在UITextField的右侧添加一个X按钮来清除文本?我在iPhone OS 2.2 SDK的Interface Builder中找不到用于添加此子控件的属性。
注意:在Xcode 4
此按钮是一个内置的 - 在由UITextField类提供的覆盖中,但是从iPhone OS 2.2 SDK开始,没有任何方法通过Interface Builder设置它。
将这行代码添加到某处(例如viewDidLoad):
myUITextField.clearButtonMode = UITextFieldViewModeWhileEditing;
UPDATE: Xcode IB的最新版本支持此属性。/ p>
How do you add that little "X" button on the right side of a UITextField that clears the text? I can't find an attribute for adding this sub-control in Interface Builder in the iPhone OS 2.2 SDK.
Note: In Xcode 4.x and later (iPhone 3.0 SDK and later), you can do this in Interface Builder.
This button is a built-in overlay that is provided by the UITextField class, but as of the iPhone OS 2.2 SDK, there isn't any way to set it via Interface Builder. You have to enable it programmatically.
Add this line of code somewhere (viewDidLoad, for example):
myUITextField.clearButtonMode = UITextFieldViewModeWhileEditing;
UPDATE: The latest version of Xcode IB does support this property.
这篇关于添加“清除”按钮到iPhone UITextField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!