UITextFieldDelegate protocol, uitextfielddelegate

Source: Internet
Author: User

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;
 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.