IOS UITextField event list

//UITextFieldDelegate
import UIKit
class ViewController:UIViewController,UITextFieldDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view,typically from a nib.
let rect = CGRect(x:10, y:80, width:300, height:
)
let textField = UITextField(frame:rect)
textField.placeholder = “Bank card no”
textField.autocorrectionType =UITextAutocorrectionType.no
textField.returnKeyType = UIReturnKeyType.done
textField.clearButtonMode =UITextFieldViewMode.whileEditing
textField.keyboardType = UIKeyboardType.numberPad
textField.keyboardAppearance =
UIKeyboardAppearance.dark
textField.delegate = self
textField.borderStyle = UITextBorderStyle.line
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func textFieldShouldBeginEditing(_ textField:UITextField) -> Bool
// return NO to disallow editing.
{
return true
}
func textFieldDidBeginEditing(_ textField:UITextField)
// became first responder
{
}
func textFieldShouldEndEditing(_ textField:UITextField) -> Bool
// return YES to allow editing to stopand to resign first responder status.NO to disallow the editing session to end
{
return true
}
func textFieldDidEndEditing(_ textField:UITextField)
// may be called if forced even if shouldEndEditing returnsNO (e.g.view removed from window) or endEditing:YES called
{
}
func textField(_ textField:UITextField,shouldChangeCharactersIn range:NSRange,replacementString string:String) -> Bool {
// return NO to not change text
return true
}
func textFieldShouldClear(_ textField:UITextField) -> Bool {
return true
}
func textFieldShouldReturn(_ textField:UITextField)-> Bool {
return true
}
}

// method comprising:
the agreement calls this method when you want to start editing state.
Calling this method editing status agreement after the start.
Editing state will call this method after the agreement to an end.
Edit call this method after the agreement states.
Protocol method called when the text to be input.
A protocol method returns BOOL value indicating whether to allow the request to clear the contents according to a user.
A protocol method returns BOOL value indicating whether to allow the end of the editing when the Enter key is pressed.

Guess you like

Origin blog.csdn.net/weixin_34362875/article/details/90866444