There is usually a need to limit the number of words in the text input. If the input is not confirmed and the characters are highlighted, then if you directly take the number of characters in the text box, the result is highlighted (that is, the characters have not been confirmed). The following figure shows an example:

UITextRange *textRange = [self.textField markedTextRange];
@property (nullable, nonatomic, readonly) UITextRange *markedTextRange; // Nil if no marked text.

The following is an example:

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textFieldDidChange:) name:UITextFieldTextDidChangeNotification object:nil];
    //======================
    - (void)textFieldDidChange:(NSNotification *)noti
{
    UITextField *textField = (UITextField *)noti.object;
    if ([textField isEqual:self.textField]) {
        UITextRange *textRange = [self.textField markedTextRange];
        if(! TextRange) {// Calculates and intercepts input characters when nilif(self.textField.text.length > 10) { self.textField.text = [self.textField.text substringToIndex:10]; }}}}Copy the code

The above is just a point about the text box input, if there is a better plan, welcome to leave a message to communicate.