0

How can I change clear button color or background color in UITextField. I tried get subviews of textField, but in subviews not clear button.

tomerpacific
  • 4,704
  • 13
  • 34
  • 52
Ash Khachatryan
  • 427
  • 1
  • 5
  • 18
  • refer this [link](https://stackoverflow.com/questions/27944781/how-to-change-the-tint-color-of-the-clear-button-on-a-uitextfield) – Dhaval Raval Dec 03 '19 at 09:24

1 Answers1

2
import UIKit

class CustomTextField: UITextField {

    override func layoutSubviews() {
        super.layoutSubviews()

        for view in subviews {
            if let button = view as? UIButton {
                button.setImage(button.image(for: .normal)?.withRenderingMode(.alwaysTemplate), for: .normal)
                button.tintColor = .white
            }
        }
    }
}
Zouhair Sassi
  • 1,403
  • 1
  • 13
  • 30
savan patel
  • 254
  • 1
  • 5
  • Thanks for answer, Can you say how can I change content color of button? I want change cross color. Now cross color is text field background color. – Ash Khachatryan Dec 03 '19 at 11:46