[swift4.2] iOS中UITextField通过exte
作者:
亡鱼 | 来源:发表于
2019-03-20 10:24 被阅读0次
// MARK: -添加自定义清除按钮
extension UITextField {
///给UITextField添加一个清除按钮
func setModifyClearButton() {
let clearButton = UIButton(type: .custom)
clearButton.setImage(UIImage(named: "textfield_clear_btn"), for: .normal)
clearButton.frame = CGRect(x: 0, y: 0, width: 35, height: 35)
clearButton.contentMode = .scaleAspectFit
clearButton.addTarget(self, action: #selector(UITextField.clear(sender:)), for: .touchUpInside)
self.rightView = clearButton
self.rightViewMode = .whileEditing
}
/// 点击清除按钮,清空内容
@objc func clear(sender: AnyObject) {
self.text = ""
}
}
本文标题:[swift4.2] iOS中UITextField通过exte
本文链接:https://www.haomeiwen.com/subject/sboamqtx.html
网友评论