1

I want to resize the default clear button of UITextField. After I googled a lot, I came to know there is no way to modify it.

So I decided to go with Custom option ie, by adding UIButton to text field.I found some code from S.O, but nothing works for me. These are the links which I referred.

So please suggest some solution which behaves exactly as default clear button of UITextField

Any help will be appreciated.

Thanks in advance.

Community
  • 1
  • 1
NSUserDefault
  • 1,794
  • 1
  • 17
  • 38

2 Answers2

3

In addition to the jake9115 response, you can emulate the clearbutton behavior by using the UITextFieldDelegate callbacks.

You can try in this way:
Show the button when -textFieldDidBeginEditing: is called
Hide the button when -textFieldDidEndEditing: is called
Hide the button if in -(BOOL)textFieldShouldClear:(UITextField*)textField the length of the textField's text is 0.

Mat
  • 7,613
  • 4
  • 40
  • 56
2

Why not just make a button that sets the TextView's value to ""?

- (IBAction)button:(id)sender {
_myTextView.text = "";
}
jake9115
  • 3,964
  • 12
  • 49
  • 78
  • But I want the button to behave exactly how default clear button works.It should appear once user start typing and disappear after clearing. – NSUserDefault May 12 '13 at 05:28