views:

3546

answers:

2

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 the iPhone 3.0 SDK, you can do this in Interface Builder.

+21  A: 

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;
Kristopher Johnson
A: 

Thanks Christopher, I was unable to find this information.

JLM