UITextFieldDelegate protocol, uitextfielddelegate
Many people think that UITextField is very simple. Why does it write this protocol?
Because it may be used in actual development;
For example:
The underline color under the text box changes with the input state;
Click the corresponding text box, the lines under it change to green, and the edit ends to Gray;
You must be familiar with the UITextFieldDelegate protocol to achieve this;
First, let's take a look at the official instructions:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField; // return NO to disallow editing.- (void)textFieldDidBeginEditing:(UITextField *)textField; // became first responder- (BOOL)textFieldShouldEndEditing:(UITextField *)textField; // return YES to allow editing to stop and to resign first responder status. NO to disallow the editing session to end- (void)textFieldDidEndEditing:(UITextField *)textField; // may be called if forced even if shouldEndEditing returns NO (e.g. view removed from window) or endEditing:YES called- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string; // return NO to not change text- (BOOL)textFieldShouldClear:(UITextField *)textField; // called when clear button pressed. return NO to ignore (no notifications)- (BOOL)textFieldShouldReturn:(UITextField *)textField; // called when 'return' key pressed. return NO to ignore.
1,
- (void)textFieldDidBeginEditing:(UITextField *)textField;
The text box has been edited.
2,
- (void)textFieldDidEndEditing:(UITextField *)textField;
The text box has been edited.
3. Whether other settings allow input control
1.-(BOOL) textFieldShouldBeginEditing :( UITextField *) textField; // return NO to disallow editing.
// Control whether input is allowed. input is prohibited when the returned value is NO;
2.-(BOOL) textFieldShouldEndEditing :( UITextField *) textField; // return YES to allow editing to stop and to resign first responder status. NO to disallow the editing session to end // whether to end the input. If the return value is YES, stop the input and release the first response. If NO is returned, the opposite is true; 3.-(BOOL) textField :( UITextField *) textField shouldChangeCharactersInRange :( nsange) range replacementString :( NSString *) string; // return NO to not change text
// Whether to change the input text. If NO is returned, do not save the modification.
4.-(BOOL) textFieldShouldClear :( UITextField *) textField; // called when clear button pressed. return NO to ignore (no notifications)
// Call the Clear button and ignore the empty button when NO is returned.
5.-(BOOL) textFieldShouldReturn :( UITextField *) textField; // called when 'Return 'key pressed. return NO to ignore.
// Call this method when you click the return button. If NO is returned, NO response is returned;