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

2
  • Where do you initialize R Commented Aug 2, 2018 at 23:18
  • I have faced same issue as I have set padding for my textfields. Resolved the issue by referring stackoverflow.com/a/10274246/10005005 Commented Nov 14, 2019 at 9:55

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.