1

I have a UITextField for search in my Application.

When user taps on the Clear Button in the right of the Search Text Field I need to hide this textfield.

So, can I show the Clear Button then TextField is empty? I need to do it always to provide the ability hiding TextField.

Oleksandr Balabanov
  • 629
  • 1
  • 6
  • 30
  • 1
    Possible duplicate of [How to show Xbutton(clear button) always visible in uisearchbar](http://stackoverflow.com/questions/18207893/how-to-show-xbuttonclear-button-always-visible-in-uisearchbar) – Stonz2 Oct 07 '15 at 14:08

2 Answers2

0

Just create a Custom button and set it as rightView for your TextField

UIButton *cleanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
// Set clear image for your button
[cleanBtn setImage:img forState:UIControlStateNormal];
[cleanBtn addTarget:self action:@selector(cleanTextField:) forControlEvents:UIControlEventTouchUpInside];

yourTextField.rightViewMode = UITextFieldViewModeAlways;
yourTextField.rightView = cleanBtn;
l0gg3r
  • 8,864
  • 3
  • 26
  • 46
0

I tried to fix this issue with creating a custom button and setting the rightView of my text field. It did not solve my problem. There is no button on the right view.

I have added UIButton in Interface Builder using Auto Layout and placed it on my text field. It works. It's strange solution but it works.

Oleksandr Balabanov
  • 629
  • 1
  • 6
  • 30