Custom UITextField clear button

前端 未结 7 888
渐次进展
渐次进展 2021-01-31 08:16

Is it possible to customize the image of the clear button in a UITextField? I have a dark textfield background and the \"x\" is not visible enough.

7条回答
  •  误落风尘
    2021-01-31 09:01

    depends on @Tuss László's answer

    Swift 3.0

    myTextField.clearButtonMode = .whileEditing
    if let clearButton = myTextField.value(forKeyPath: "_clearButton") as? UIButton {
        clearButton.setImage(UIImage(named:"myImage"), for: .normal)
        clearButton.setImage(UIImage(named:"myImage"), for: .highlighted)
    }
    

    But really use it carefully. If Apple change implementations in future iOS releases, it would not be work

提交回复
热议问题