我的问题是,如果我自定义UITextField,那么不会调用shouldChangeCharactersIn()方法,但如果我不适用于此自定义,一切都会顺利。
我使用库SkyFloatingLabelTextField
第一档:
override func viewDidLoad() {
super.viewDidLoad()
emailField.setRegistrationFieldStyleWith(title: "E-mail")
emailField.delegate = self
}
带扩展程序的第二个文件:
func setRegistrationFieldStyleWith(title: String) {
let textField = SkyFloatingLabelTextField(frame: CGRect(x: 0, y: 0, width: 215, height: 40))
textField.placeholder = title
textField.title = title
textField.tintColor = overcastBlueColor
...
...
self.addSubview(textField)
}
也许谁面对这个图书馆?或者输入处理方法开始表现不同,如果要自定义字段?
答案 0 :(得分:1)
试试这个
override func viewDidLoad() {
super.viewDidLoad()
emailField.setRegistrationFieldStyleWith(title: "E-mail")
for view in emailField.subviews {
if view.isKind(of: UITextField.self) {
let textFieldView = view as! UITextField
textFieldView.delegate = self
}
}
}