0

I'm facing a problem while trying to enable the clear button on UITextField. I have added like this:

if let clearButton = searchTextField.value(forKeyPath: "_clearButton") as? UIButton { //KV
    clearButton.tintColor = .nextWhite()
    clearButton.backgroundColor = .nextWhite()
    clearButton.setImage(UIImage(named: R.image.iconCloseRounded.name), for: .normal)
    clearButton.isHidden = false

The debug 3d image is attached on the link below.

Please, could anyone see where I'm adding this wrong that it's not being shown?

enter image description here

enter image description here

rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

0

I have copied your code, it is working fine.

But you have to make sure that in the dropdown menu for "Clear Button" there is something other checked than "never appears".

Picture of that dropdown menu

Or if you want to activate it from code use:

searchTextField.clearButtonMode = UITextFieldViewMode.whileEditing

reference: https://stackoverflow.com/a/320079/1898677

laka
  • 644
  • 8
  • 23