UITextField初始化
let testTextField = UITextField(frame: CGRect(x: 100, y: 100, width: 200, height: 44))
边框样式设置
//UITextBorderStyle:RoundedRect None Line Bezel
testTextField.borderStyle = .RoundedRect
其他设置
//UIReturnKeyType:Default Done Search Next...
testTextField.returnKeyType = .Done
//安全输入
testTextField.secureTextEntry = true
...
键盘
//弹出键盘
testTextField.becomeFirstResponder()
//收起键盘
testTextField.resignFirstResponder()
代理
UITextFieldDelegate
testTextField.delegate = self
func testButtonClick(btn:UIButton) -> Void {
print("click")
}
func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
print("将要开始编辑")
return true
}
func textFieldDidBeginEditing(textField: UITextField) {
print("开始编辑")
}
func textFieldDidEndEditing(textField: UITextField) {
print("已经结束")
}
...